protoc 2.6.1.1 → 2.6.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/protoc/Makefile.in +10 -13
- data/ext/protoc/extconf.rb +0 -1
- data/ext/protoc/protobuf/CHANGES.txt +593 -0
- data/ext/protoc/protobuf/CONTRIBUTORS.txt +93 -0
- data/ext/protoc/protobuf/INSTALL.txt +237 -0
- data/ext/protoc/protobuf/LICENSE +33 -0
- data/ext/protoc/protobuf/Makefile.am +267 -0
- data/ext/protoc/protobuf/README.md +167 -0
- data/ext/protoc/protobuf/autogen.sh +41 -0
- data/ext/protoc/protobuf/benchmarks/ProtoBench.java +203 -0
- data/ext/protoc/protobuf/benchmarks/google_message1.dat +0 -0
- data/ext/protoc/protobuf/benchmarks/google_message2.dat +0 -0
- data/ext/protoc/protobuf/benchmarks/google_size.proto +136 -0
- data/ext/protoc/protobuf/benchmarks/google_speed.proto +136 -0
- data/ext/protoc/protobuf/benchmarks/readme.txt +50 -0
- data/ext/protoc/protobuf/configure.ac +159 -0
- data/ext/protoc/protobuf/editors/README.txt +5 -0
- data/ext/protoc/protobuf/editors/proto.vim +105 -0
- data/ext/protoc/protobuf/editors/protobuf-mode.el +220 -0
- data/ext/protoc/protobuf/examples/AddPerson.java +95 -0
- data/ext/protoc/protobuf/examples/ListPeople.java +50 -0
- data/ext/protoc/protobuf/examples/Makefile +58 -0
- data/ext/protoc/protobuf/examples/README.txt +29 -0
- data/ext/protoc/protobuf/examples/add_person.cc +95 -0
- data/ext/protoc/protobuf/examples/add_person.py +58 -0
- data/ext/protoc/protobuf/examples/addressbook.proto +30 -0
- data/ext/protoc/protobuf/examples/list_people.cc +68 -0
- data/ext/protoc/protobuf/examples/list_people.py +38 -0
- data/ext/protoc/protobuf/generate_descriptor_proto.sh +33 -0
- data/ext/protoc/protobuf/java/README.txt +96 -0
- data/ext/protoc/protobuf/java/pom.xml +217 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessage.java +466 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +355 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractParser.java +253 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +51 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingService.java +64 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BoundedByteString.java +163 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ByteString.java +1022 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedInputStream.java +1311 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedOutputStream.java +1297 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Descriptors.java +2238 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/DynamicMessage.java +622 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Extension.java +96 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +392 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +185 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/FieldSet.java +907 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessage.java +2213 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +949 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Internal.java +391 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +122 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyField.java +154 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyFieldLite.java +176 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +367 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringList.java +163 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LiteralByteString.java +362 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Message.java +244 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLite.java +320 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +60 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +143 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageReflection.java +931 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Parser.java +261 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +58 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolStringList.java +48 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +696 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RopeByteString.java +957 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcCallback.java +47 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcChannel.java +71 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcController.java +118 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcUtil.java +134 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Service.java +117 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ServiceException.java +52 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +241 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SmallSortedMap.java +618 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/TextFormat.java +1984 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +99 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +995 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +205 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Utf8.java +349 -0
- data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/WireFormat.java +163 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +527 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +68 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ByteStringTest.java +759 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +141 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +769 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +401 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +80 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DescriptorsTest.java +735 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +326 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +48 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +1515 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +180 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +421 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +134 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldTest.java +121 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +319 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +174 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +143 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +85 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteTest.java +148 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +396 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/MessageTest.java +353 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +185 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ParserTest.java +381 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +190 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +97 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +115 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ServiceTest.java +320 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +155 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +420 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +96 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java +4124 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TextFormatTest.java +994 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +653 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +227 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/WireFormatTest.java +606 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +61 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +55 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/multiple_files_test.proto +77 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_builders_test.proto +53 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension.proto +46 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +48 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension.proto +49 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +50 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +38 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +42 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +43 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +157 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8.proto +50 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +51 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_custom_options.proto +43 -0
- data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +60 -0
- data/ext/protoc/protobuf/m4/ac_system_extensions.m4 +37 -0
- data/ext/protoc/protobuf/m4/acx_check_suncc.m4 +75 -0
- data/ext/protoc/protobuf/m4/acx_pthread.m4 +397 -0
- data/ext/protoc/protobuf/m4/stl_hash.m4 +72 -0
- data/ext/protoc/protobuf/more_tests/Makefile +41 -0
- data/ext/protoc/protobuf/post_process_dist.sh +60 -0
- data/ext/protoc/protobuf/protobuf-lite.pc.in +13 -0
- data/ext/protoc/protobuf/protobuf.pc.in +14 -0
- data/ext/protoc/protobuf/python/README.txt +105 -0
- data/ext/protoc/protobuf/python/ez_setup.py +284 -0
- data/ext/protoc/protobuf/python/google/__init__.py +1 -0
- data/ext/protoc/protobuf/python/google/protobuf/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor.py +849 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor_database.py +137 -0
- data/ext/protoc/protobuf/python/google/protobuf/descriptor_pool.py +643 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.cc +139 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.py +89 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation_default_test.py +63 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/containers.py +269 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/cpp_message.py +663 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/decoder.py +831 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_database_test.py +63 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +564 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto +94 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto +70 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_test.py +669 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/encoder.py +788 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/enum_type_wrapper.py +89 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test1.proto +57 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test2.proto +92 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/generator_test.py +343 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_test.py +131 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_listener.py +78 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_python_test.py +54 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/message_test.py +681 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/missing_enum_values.proto +50 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions.proto +58 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto +49 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/more_messages.proto +51 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/python_message.py +1251 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/reflection_test.py +2934 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/service_reflection_test.py +136 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/symbol_database_test.py +120 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto +52 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/test_util.py +662 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/text_encoding_test.py +68 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/text_format_test.py +743 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/type_checkers.py +328 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/unknown_fields_test.py +231 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format.py +268 -0
- data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format_test.py +253 -0
- data/ext/protoc/protobuf/python/google/protobuf/message.py +284 -0
- data/ext/protoc/protobuf/python/google/protobuf/message_factory.py +155 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/README +6 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/__init__.py +0 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/cpp_message.py +61 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.cc +357 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.h +96 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor_cpp2_test.py +58 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.cc +338 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.h +123 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message.cc +2561 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message.h +305 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/message_factory_cpp2_test.py +56 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/proto2_api_test.proto +38 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/python.proto +66 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/python_protobuf.h +57 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +94 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +763 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +172 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +825 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +112 -0
- data/ext/protoc/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +95 -0
- data/ext/protoc/protobuf/python/google/protobuf/reflection.py +205 -0
- data/ext/protoc/protobuf/python/google/protobuf/service.py +226 -0
- data/ext/protoc/protobuf/python/google/protobuf/service_reflection.py +284 -0
- data/ext/protoc/protobuf/python/google/protobuf/symbol_database.py +185 -0
- data/ext/protoc/protobuf/python/google/protobuf/text_encoding.py +110 -0
- data/ext/protoc/protobuf/python/google/protobuf/text_format.py +873 -0
- data/ext/protoc/protobuf/python/mox.py +1401 -0
- data/ext/protoc/protobuf/python/setup.py +201 -0
- data/ext/protoc/protobuf/python/stubout.py +140 -0
- data/ext/protoc/protobuf/src/Makefile.am +418 -0
- data/ext/protoc/protobuf/src/google/protobuf/SEBS +240 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.cc +84 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.h +145 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.cc +1603 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.h +378 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +1654 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc +288 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h +103 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +431 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h +122 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc +210 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h +86 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h +185 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc +665 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc +125 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc +494 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h +206 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc +2645 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h +175 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc +375 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h +58 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +123 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +451 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +123 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc +334 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc +642 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h +127 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +132 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc +2074 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.cc +480 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.h +317 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/importer_unittest.cc +617 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.cc +195 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.h +95 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc +233 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h +69 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc +67 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.cc +333 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.h +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc +778 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.h +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.cc +207 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.h +109 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.cc +213 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.h +162 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.cc +534 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.h +115 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.cc +158 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc +77 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h +101 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.cc +737 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.h +322 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc +826 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.cc +1666 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.h +140 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.cc +1343 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.h +173 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc +266 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h +124 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc +124 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc +877 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h +160 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.cc +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.h +135 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc +201 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h +90 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.cc +1056 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.h +160 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/main.cc +61 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +240 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.h +117 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.cc +1750 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.h +522 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/parser_unittest.cc +2612 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.cc +163 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.h +72 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.cc +1148 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.h +897 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.proto +147 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.cc +1262 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.h +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc +118 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.cc +463 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/test_plugin.cc +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh +91 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.cc +218 -0
- data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.cc +5420 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.h +1691 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.cc +9135 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.h +6761 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor.proto +687 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.cc +543 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.h +369 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_database_unittest.cc +748 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_pb2_test.py +54 -0
- data/ext/protoc/protobuf/src/google/protobuf/descriptor_unittest.cc +5501 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.cc +764 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.h +148 -0
- data/ext/protoc/protobuf/src/google/protobuf/dynamic_message_unittest.cc +230 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set.cc +1663 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set.h +1234 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set_heavy.cc +734 -0
- data/ext/protoc/protobuf/src/google/protobuf/extension_set_unittest.cc +1095 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_enum_reflection.h +91 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.cc +1683 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.h +504 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +795 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.cc +65 -0
- data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.h +113 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.cc +914 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.h +1220 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_inl.h +69 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +1378 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.cc +326 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.h +209 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh +44 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer.cc +198 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer.h +136 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/printer_unittest.cc +285 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/strtod.cc +113 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/strtod.h +50 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.cc +1127 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.h +402 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +999 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.cc +57 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.h +248 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +358 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +405 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +354 -0
- data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +965 -0
- data/ext/protoc/protobuf/src/google/protobuf/lite_unittest.cc +350 -0
- data/ext/protoc/protobuf/src/google/protobuf/message.cc +358 -0
- data/ext/protoc/protobuf/src/google/protobuf/message.h +866 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_lite.cc +335 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_lite.h +247 -0
- data/ext/protoc/protobuf/src/google/protobuf/message_unittest.cc +427 -0
- data/ext/protoc/protobuf/src/google/protobuf/package_info.h +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.cc +269 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.h +81 -0
- data/ext/protoc/protobuf/src/google/protobuf/reflection_ops_unittest.cc +475 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field.cc +87 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field.h +1603 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +195 -0
- data/ext/protoc/protobuf/src/google/protobuf/repeated_field_unittest.cc +1442 -0
- data/ext/protoc/protobuf/src/google/protobuf/service.cc +46 -0
- data/ext/protoc/protobuf/src/google/protobuf/service.h +291 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops.h +227 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +325 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +151 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +146 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +122 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +137 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_macosx.h +225 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +313 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_pnacl.h +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h +188 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h +219 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc +137 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +293 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +112 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +150 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common.cc +395 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common.h +1226 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/common_unittest.cc +357 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/hash.h +232 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/map_util.h +771 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once.cc +99 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once.h +166 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/once_unittest.cc +253 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/platform_macros.h +103 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/shared_ptr.h +470 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stl_util.h +121 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.cc +175 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.h +76 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc +152 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid.cc +536 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +40 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.cc +1279 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.h +562 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.cc +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util.h +138 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util_unittest.cc +130 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits.h +336 -0
- data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc +628 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util.cc +3345 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util.h +215 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.cc +1585 -0
- data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/bad_utf8_string +1 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_packed_fields_message +0 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt +129 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt +129 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt +134 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/file.cc +194 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/file.h +97 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.cc +255 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.h +102 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/zcgunzip.cc +73 -0
- data/ext/protoc/protobuf/src/google/protobuf/testing/zcgzip.cc +79 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format.cc +1746 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format.h +473 -0
- data/ext/protoc/protobuf/src/google/protobuf/text_format_unittest.cc +1479 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest.proto +861 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_custom_options.proto +393 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto +50 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_empty.proto +37 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto +1046 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import.proto +64 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_lite.proto +51 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public.proto +40 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public_lite.proto +42 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_lite.proto +384 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto +43 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_mset.proto +83 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_no_generic_services.proto +53 -0
- data/ext/protoc/protobuf/src/google/protobuf/unittest_optimize_for.proto +66 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.cc +265 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.h +318 -0
- data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +599 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format.cc +1101 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format.h +336 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.cc +471 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.h +661 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite_inl.h +860 -0
- data/ext/protoc/protobuf/src/google/protobuf/wire_format_unittest.cc +1120 -0
- data/ext/protoc/protobuf/src/solaris/libstdc++.la +51 -0
- data/ext/protoc/protobuf/vsprojects/config.h +29 -0
- data/ext/protoc/protobuf/vsprojects/convert2008to2005.sh +20 -0
- data/ext/protoc/protobuf/vsprojects/extract_includes.bat +50 -0
- data/ext/protoc/protobuf/vsprojects/libprotobuf-lite.vcproj +302 -0
- data/ext/protoc/protobuf/vsprojects/libprotobuf.vcproj +470 -0
- data/ext/protoc/protobuf/vsprojects/libprotoc.vcproj +466 -0
- data/ext/protoc/protobuf/vsprojects/lite-test.vcproj +305 -0
- data/ext/protoc/protobuf/vsprojects/protobuf.sln +92 -0
- data/ext/protoc/protobuf/vsprojects/protoc.vcproj +192 -0
- data/ext/protoc/protobuf/vsprojects/readme.txt +114 -0
- data/ext/protoc/protobuf/vsprojects/test_plugin.vcproj +209 -0
- data/ext/protoc/protobuf/vsprojects/tests.vcproj +681 -0
- data/lib/protoc/version.rb +1 -1
- metadata +480 -3
@@ -0,0 +1,1220 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
4
|
+
//
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
6
|
+
// modification, are permitted provided that the following conditions are
|
7
|
+
// met:
|
8
|
+
//
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
13
|
+
// in the documentation and/or other materials provided with the
|
14
|
+
// distribution.
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
17
|
+
// this software without specific prior written permission.
|
18
|
+
//
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
// Author: kenton@google.com (Kenton Varda)
|
32
|
+
// Based on original Protocol Buffers design by
|
33
|
+
// Sanjay Ghemawat, Jeff Dean, and others.
|
34
|
+
//
|
35
|
+
// This file contains the CodedInputStream and CodedOutputStream classes,
|
36
|
+
// which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively,
|
37
|
+
// and allow you to read or write individual pieces of data in various
|
38
|
+
// formats. In particular, these implement the varint encoding for
|
39
|
+
// integers, a simple variable-length encoding in which smaller numbers
|
40
|
+
// take fewer bytes.
|
41
|
+
//
|
42
|
+
// Typically these classes will only be used internally by the protocol
|
43
|
+
// buffer library in order to encode and decode protocol buffers. Clients
|
44
|
+
// of the library only need to know about this class if they wish to write
|
45
|
+
// custom message parsing or serialization procedures.
|
46
|
+
//
|
47
|
+
// CodedOutputStream example:
|
48
|
+
// // Write some data to "myfile". First we write a 4-byte "magic number"
|
49
|
+
// // to identify the file type, then write a length-delimited string. The
|
50
|
+
// // string is composed of a varint giving the length followed by the raw
|
51
|
+
// // bytes.
|
52
|
+
// int fd = open("myfile", O_WRONLY);
|
53
|
+
// ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
|
54
|
+
// CodedOutputStream* coded_output = new CodedOutputStream(raw_output);
|
55
|
+
//
|
56
|
+
// int magic_number = 1234;
|
57
|
+
// char text[] = "Hello world!";
|
58
|
+
// coded_output->WriteLittleEndian32(magic_number);
|
59
|
+
// coded_output->WriteVarint32(strlen(text));
|
60
|
+
// coded_output->WriteRaw(text, strlen(text));
|
61
|
+
//
|
62
|
+
// delete coded_output;
|
63
|
+
// delete raw_output;
|
64
|
+
// close(fd);
|
65
|
+
//
|
66
|
+
// CodedInputStream example:
|
67
|
+
// // Read a file created by the above code.
|
68
|
+
// int fd = open("myfile", O_RDONLY);
|
69
|
+
// ZeroCopyInputStream* raw_input = new FileInputStream(fd);
|
70
|
+
// CodedInputStream coded_input = new CodedInputStream(raw_input);
|
71
|
+
//
|
72
|
+
// coded_input->ReadLittleEndian32(&magic_number);
|
73
|
+
// if (magic_number != 1234) {
|
74
|
+
// cerr << "File not in expected format." << endl;
|
75
|
+
// return;
|
76
|
+
// }
|
77
|
+
//
|
78
|
+
// uint32 size;
|
79
|
+
// coded_input->ReadVarint32(&size);
|
80
|
+
//
|
81
|
+
// char* text = new char[size + 1];
|
82
|
+
// coded_input->ReadRaw(buffer, size);
|
83
|
+
// text[size] = '\0';
|
84
|
+
//
|
85
|
+
// delete coded_input;
|
86
|
+
// delete raw_input;
|
87
|
+
// close(fd);
|
88
|
+
//
|
89
|
+
// cout << "Text is: " << text << endl;
|
90
|
+
// delete [] text;
|
91
|
+
//
|
92
|
+
// For those who are interested, varint encoding is defined as follows:
|
93
|
+
//
|
94
|
+
// The encoding operates on unsigned integers of up to 64 bits in length.
|
95
|
+
// Each byte of the encoded value has the format:
|
96
|
+
// * bits 0-6: Seven bits of the number being encoded.
|
97
|
+
// * bit 7: Zero if this is the last byte in the encoding (in which
|
98
|
+
// case all remaining bits of the number are zero) or 1 if
|
99
|
+
// more bytes follow.
|
100
|
+
// The first byte contains the least-significant 7 bits of the number, the
|
101
|
+
// second byte (if present) contains the next-least-significant 7 bits,
|
102
|
+
// and so on. So, the binary number 1011000101011 would be encoded in two
|
103
|
+
// bytes as "10101011 00101100".
|
104
|
+
//
|
105
|
+
// In theory, varint could be used to encode integers of any length.
|
106
|
+
// However, for practicality we set a limit at 64 bits. The maximum encoded
|
107
|
+
// length of a number is thus 10 bytes.
|
108
|
+
|
109
|
+
#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
|
110
|
+
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
|
111
|
+
|
112
|
+
#include <string>
|
113
|
+
#ifdef _MSC_VER
|
114
|
+
#if defined(_M_IX86) && \
|
115
|
+
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
|
116
|
+
#define PROTOBUF_LITTLE_ENDIAN 1
|
117
|
+
#endif
|
118
|
+
#if _MSC_VER >= 1300
|
119
|
+
// If MSVC has "/RTCc" set, it will complain about truncating casts at
|
120
|
+
// runtime. This file contains some intentional truncating casts.
|
121
|
+
#pragma runtime_checks("c", off)
|
122
|
+
#endif
|
123
|
+
#else
|
124
|
+
#include <sys/param.h> // __BYTE_ORDER
|
125
|
+
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN && \
|
126
|
+
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
|
127
|
+
#define PROTOBUF_LITTLE_ENDIAN 1
|
128
|
+
#endif
|
129
|
+
#endif
|
130
|
+
#include <google/protobuf/stubs/common.h>
|
131
|
+
|
132
|
+
|
133
|
+
namespace google {
|
134
|
+
namespace protobuf {
|
135
|
+
|
136
|
+
class DescriptorPool;
|
137
|
+
class MessageFactory;
|
138
|
+
|
139
|
+
namespace io {
|
140
|
+
|
141
|
+
// Defined in this file.
|
142
|
+
class CodedInputStream;
|
143
|
+
class CodedOutputStream;
|
144
|
+
|
145
|
+
// Defined in other files.
|
146
|
+
class ZeroCopyInputStream; // zero_copy_stream.h
|
147
|
+
class ZeroCopyOutputStream; // zero_copy_stream.h
|
148
|
+
|
149
|
+
// Class which reads and decodes binary data which is composed of varint-
|
150
|
+
// encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream.
|
151
|
+
// Most users will not need to deal with CodedInputStream.
|
152
|
+
//
|
153
|
+
// Most methods of CodedInputStream that return a bool return false if an
|
154
|
+
// underlying I/O error occurs or if the data is malformed. Once such a
|
155
|
+
// failure occurs, the CodedInputStream is broken and is no longer useful.
|
156
|
+
class LIBPROTOBUF_EXPORT CodedInputStream {
|
157
|
+
public:
|
158
|
+
// Create a CodedInputStream that reads from the given ZeroCopyInputStream.
|
159
|
+
explicit CodedInputStream(ZeroCopyInputStream* input);
|
160
|
+
|
161
|
+
// Create a CodedInputStream that reads from the given flat array. This is
|
162
|
+
// faster than using an ArrayInputStream. PushLimit(size) is implied by
|
163
|
+
// this constructor.
|
164
|
+
explicit CodedInputStream(const uint8* buffer, int size);
|
165
|
+
|
166
|
+
// Destroy the CodedInputStream and position the underlying
|
167
|
+
// ZeroCopyInputStream at the first unread byte. If an error occurred while
|
168
|
+
// reading (causing a method to return false), then the exact position of
|
169
|
+
// the input stream may be anywhere between the last value that was read
|
170
|
+
// successfully and the stream's byte limit.
|
171
|
+
~CodedInputStream();
|
172
|
+
|
173
|
+
// Return true if this CodedInputStream reads from a flat array instead of
|
174
|
+
// a ZeroCopyInputStream.
|
175
|
+
inline bool IsFlat() const;
|
176
|
+
|
177
|
+
// Skips a number of bytes. Returns false if an underlying read error
|
178
|
+
// occurs.
|
179
|
+
bool Skip(int count);
|
180
|
+
|
181
|
+
// Sets *data to point directly at the unread part of the CodedInputStream's
|
182
|
+
// underlying buffer, and *size to the size of that buffer, but does not
|
183
|
+
// advance the stream's current position. This will always either produce
|
184
|
+
// a non-empty buffer or return false. If the caller consumes any of
|
185
|
+
// this data, it should then call Skip() to skip over the consumed bytes.
|
186
|
+
// This may be useful for implementing external fast parsing routines for
|
187
|
+
// types of data not covered by the CodedInputStream interface.
|
188
|
+
bool GetDirectBufferPointer(const void** data, int* size);
|
189
|
+
|
190
|
+
// Like GetDirectBufferPointer, but this method is inlined, and does not
|
191
|
+
// attempt to Refresh() if the buffer is currently empty.
|
192
|
+
inline void GetDirectBufferPointerInline(const void** data,
|
193
|
+
int* size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
194
|
+
|
195
|
+
// Read raw bytes, copying them into the given buffer.
|
196
|
+
bool ReadRaw(void* buffer, int size);
|
197
|
+
|
198
|
+
// Like ReadRaw, but reads into a string.
|
199
|
+
//
|
200
|
+
// Implementation Note: ReadString() grows the string gradually as it
|
201
|
+
// reads in the data, rather than allocating the entire requested size
|
202
|
+
// upfront. This prevents denial-of-service attacks in which a client
|
203
|
+
// could claim that a string is going to be MAX_INT bytes long in order to
|
204
|
+
// crash the server because it can't allocate this much space at once.
|
205
|
+
bool ReadString(string* buffer, int size);
|
206
|
+
// Like the above, with inlined optimizations. This should only be used
|
207
|
+
// by the protobuf implementation.
|
208
|
+
inline bool InternalReadStringInline(string* buffer,
|
209
|
+
int size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
210
|
+
|
211
|
+
|
212
|
+
// Read a 32-bit little-endian integer.
|
213
|
+
bool ReadLittleEndian32(uint32* value);
|
214
|
+
// Read a 64-bit little-endian integer.
|
215
|
+
bool ReadLittleEndian64(uint64* value);
|
216
|
+
|
217
|
+
// These methods read from an externally provided buffer. The caller is
|
218
|
+
// responsible for ensuring that the buffer has sufficient space.
|
219
|
+
// Read a 32-bit little-endian integer.
|
220
|
+
static const uint8* ReadLittleEndian32FromArray(const uint8* buffer,
|
221
|
+
uint32* value);
|
222
|
+
// Read a 64-bit little-endian integer.
|
223
|
+
static const uint8* ReadLittleEndian64FromArray(const uint8* buffer,
|
224
|
+
uint64* value);
|
225
|
+
|
226
|
+
// Read an unsigned integer with Varint encoding, truncating to 32 bits.
|
227
|
+
// Reading a 32-bit value is equivalent to reading a 64-bit one and casting
|
228
|
+
// it to uint32, but may be more efficient.
|
229
|
+
bool ReadVarint32(uint32* value);
|
230
|
+
// Read an unsigned integer with Varint encoding.
|
231
|
+
bool ReadVarint64(uint64* value);
|
232
|
+
|
233
|
+
// Read a tag. This calls ReadVarint32() and returns the result, or returns
|
234
|
+
// zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates
|
235
|
+
// the last tag value, which can be checked with LastTagWas().
|
236
|
+
// Always inline because this is only called in one place per parse loop
|
237
|
+
// but it is called for every iteration of said loop, so it should be fast.
|
238
|
+
// GCC doesn't want to inline this by default.
|
239
|
+
uint32 ReadTag() GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
240
|
+
|
241
|
+
// This usually a faster alternative to ReadTag() when cutoff is a manifest
|
242
|
+
// constant. It does particularly well for cutoff >= 127. The first part
|
243
|
+
// of the return value is the tag that was read, though it can also be 0 in
|
244
|
+
// the cases where ReadTag() would return 0. If the second part is true
|
245
|
+
// then the tag is known to be in [0, cutoff]. If not, the tag either is
|
246
|
+
// above cutoff or is 0. (There's intentional wiggle room when tag is 0,
|
247
|
+
// because that can arise in several ways, and for best performance we want
|
248
|
+
// to avoid an extra "is tag == 0?" check here.)
|
249
|
+
inline std::pair<uint32, bool> ReadTagWithCutoff(uint32 cutoff)
|
250
|
+
GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
251
|
+
|
252
|
+
// Usually returns true if calling ReadVarint32() now would produce the given
|
253
|
+
// value. Will always return false if ReadVarint32() would not return the
|
254
|
+
// given value. If ExpectTag() returns true, it also advances past
|
255
|
+
// the varint. For best performance, use a compile-time constant as the
|
256
|
+
// parameter.
|
257
|
+
// Always inline because this collapses to a small number of instructions
|
258
|
+
// when given a constant parameter, but GCC doesn't want to inline by default.
|
259
|
+
bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
260
|
+
|
261
|
+
// Like above, except this reads from the specified buffer. The caller is
|
262
|
+
// responsible for ensuring that the buffer is large enough to read a varint
|
263
|
+
// of the expected size. For best performance, use a compile-time constant as
|
264
|
+
// the expected tag parameter.
|
265
|
+
//
|
266
|
+
// Returns a pointer beyond the expected tag if it was found, or NULL if it
|
267
|
+
// was not.
|
268
|
+
static const uint8* ExpectTagFromArray(
|
269
|
+
const uint8* buffer,
|
270
|
+
uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
271
|
+
|
272
|
+
// Usually returns true if no more bytes can be read. Always returns false
|
273
|
+
// if more bytes can be read. If ExpectAtEnd() returns true, a subsequent
|
274
|
+
// call to LastTagWas() will act as if ReadTag() had been called and returned
|
275
|
+
// zero, and ConsumedEntireMessage() will return true.
|
276
|
+
bool ExpectAtEnd();
|
277
|
+
|
278
|
+
// If the last call to ReadTag() or ReadTagWithCutoff() returned the
|
279
|
+
// given value, returns true. Otherwise, returns false;
|
280
|
+
//
|
281
|
+
// This is needed because parsers for some types of embedded messages
|
282
|
+
// (with field type TYPE_GROUP) don't actually know that they've reached the
|
283
|
+
// end of a message until they see an ENDGROUP tag, which was actually part
|
284
|
+
// of the enclosing message. The enclosing message would like to check that
|
285
|
+
// tag to make sure it had the right number, so it calls LastTagWas() on
|
286
|
+
// return from the embedded parser to check.
|
287
|
+
bool LastTagWas(uint32 expected);
|
288
|
+
|
289
|
+
// When parsing message (but NOT a group), this method must be called
|
290
|
+
// immediately after MergeFromCodedStream() returns (if it returns true)
|
291
|
+
// to further verify that the message ended in a legitimate way. For
|
292
|
+
// example, this verifies that parsing did not end on an end-group tag.
|
293
|
+
// It also checks for some cases where, due to optimizations,
|
294
|
+
// MergeFromCodedStream() can incorrectly return true.
|
295
|
+
bool ConsumedEntireMessage();
|
296
|
+
|
297
|
+
// Limits ----------------------------------------------------------
|
298
|
+
// Limits are used when parsing length-delimited embedded messages.
|
299
|
+
// After the message's length is read, PushLimit() is used to prevent
|
300
|
+
// the CodedInputStream from reading beyond that length. Once the
|
301
|
+
// embedded message has been parsed, PopLimit() is called to undo the
|
302
|
+
// limit.
|
303
|
+
|
304
|
+
// Opaque type used with PushLimit() and PopLimit(). Do not modify
|
305
|
+
// values of this type yourself. The only reason that this isn't a
|
306
|
+
// struct with private internals is for efficiency.
|
307
|
+
typedef int Limit;
|
308
|
+
|
309
|
+
// Places a limit on the number of bytes that the stream may read,
|
310
|
+
// starting from the current position. Once the stream hits this limit,
|
311
|
+
// it will act like the end of the input has been reached until PopLimit()
|
312
|
+
// is called.
|
313
|
+
//
|
314
|
+
// As the names imply, the stream conceptually has a stack of limits. The
|
315
|
+
// shortest limit on the stack is always enforced, even if it is not the
|
316
|
+
// top limit.
|
317
|
+
//
|
318
|
+
// The value returned by PushLimit() is opaque to the caller, and must
|
319
|
+
// be passed unchanged to the corresponding call to PopLimit().
|
320
|
+
Limit PushLimit(int byte_limit);
|
321
|
+
|
322
|
+
// Pops the last limit pushed by PushLimit(). The input must be the value
|
323
|
+
// returned by that call to PushLimit().
|
324
|
+
void PopLimit(Limit limit);
|
325
|
+
|
326
|
+
// Returns the number of bytes left until the nearest limit on the
|
327
|
+
// stack is hit, or -1 if no limits are in place.
|
328
|
+
int BytesUntilLimit() const;
|
329
|
+
|
330
|
+
// Returns current position relative to the beginning of the input stream.
|
331
|
+
int CurrentPosition() const;
|
332
|
+
|
333
|
+
// Total Bytes Limit -----------------------------------------------
|
334
|
+
// To prevent malicious users from sending excessively large messages
|
335
|
+
// and causing integer overflows or memory exhaustion, CodedInputStream
|
336
|
+
// imposes a hard limit on the total number of bytes it will read.
|
337
|
+
|
338
|
+
// Sets the maximum number of bytes that this CodedInputStream will read
|
339
|
+
// before refusing to continue. To prevent integer overflows in the
|
340
|
+
// protocol buffers implementation, as well as to prevent servers from
|
341
|
+
// allocating enormous amounts of memory to hold parsed messages, the
|
342
|
+
// maximum message length should be limited to the shortest length that
|
343
|
+
// will not harm usability. The theoretical shortest message that could
|
344
|
+
// cause integer overflows is 512MB. The default limit is 64MB. Apps
|
345
|
+
// should set shorter limits if possible. If warning_threshold is not -1,
|
346
|
+
// a warning will be printed to stderr after warning_threshold bytes are
|
347
|
+
// read. For backwards compatibility all negative values get squashed to -1,
|
348
|
+
// as other negative values might have special internal meanings.
|
349
|
+
// An error will always be printed to stderr if the limit is reached.
|
350
|
+
//
|
351
|
+
// This is unrelated to PushLimit()/PopLimit().
|
352
|
+
//
|
353
|
+
// Hint: If you are reading this because your program is printing a
|
354
|
+
// warning about dangerously large protocol messages, you may be
|
355
|
+
// confused about what to do next. The best option is to change your
|
356
|
+
// design such that excessively large messages are not necessary.
|
357
|
+
// For example, try to design file formats to consist of many small
|
358
|
+
// messages rather than a single large one. If this is infeasible,
|
359
|
+
// you will need to increase the limit. Chances are, though, that
|
360
|
+
// your code never constructs a CodedInputStream on which the limit
|
361
|
+
// can be set. You probably parse messages by calling things like
|
362
|
+
// Message::ParseFromString(). In this case, you will need to change
|
363
|
+
// your code to instead construct some sort of ZeroCopyInputStream
|
364
|
+
// (e.g. an ArrayInputStream), construct a CodedInputStream around
|
365
|
+
// that, then call Message::ParseFromCodedStream() instead. Then
|
366
|
+
// you can adjust the limit. Yes, it's more work, but you're doing
|
367
|
+
// something unusual.
|
368
|
+
void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold);
|
369
|
+
|
370
|
+
// The Total Bytes Limit minus the Current Position, or -1 if there
|
371
|
+
// is no Total Bytes Limit.
|
372
|
+
int BytesUntilTotalBytesLimit() const;
|
373
|
+
|
374
|
+
// Recursion Limit -------------------------------------------------
|
375
|
+
// To prevent corrupt or malicious messages from causing stack overflows,
|
376
|
+
// we must keep track of the depth of recursion when parsing embedded
|
377
|
+
// messages and groups. CodedInputStream keeps track of this because it
|
378
|
+
// is the only object that is passed down the stack during parsing.
|
379
|
+
|
380
|
+
// Sets the maximum recursion depth. The default is 100.
|
381
|
+
void SetRecursionLimit(int limit);
|
382
|
+
|
383
|
+
|
384
|
+
// Increments the current recursion depth. Returns true if the depth is
|
385
|
+
// under the limit, false if it has gone over.
|
386
|
+
bool IncrementRecursionDepth();
|
387
|
+
|
388
|
+
// Decrements the recursion depth.
|
389
|
+
void DecrementRecursionDepth();
|
390
|
+
|
391
|
+
// Extension Registry ----------------------------------------------
|
392
|
+
// ADVANCED USAGE: 99.9% of people can ignore this section.
|
393
|
+
//
|
394
|
+
// By default, when parsing extensions, the parser looks for extension
|
395
|
+
// definitions in the pool which owns the outer message's Descriptor.
|
396
|
+
// However, you may call SetExtensionRegistry() to provide an alternative
|
397
|
+
// pool instead. This makes it possible, for example, to parse a message
|
398
|
+
// using a generated class, but represent some extensions using
|
399
|
+
// DynamicMessage.
|
400
|
+
|
401
|
+
// Set the pool used to look up extensions. Most users do not need to call
|
402
|
+
// this as the correct pool will be chosen automatically.
|
403
|
+
//
|
404
|
+
// WARNING: It is very easy to misuse this. Carefully read the requirements
|
405
|
+
// below. Do not use this unless you are sure you need it. Almost no one
|
406
|
+
// does.
|
407
|
+
//
|
408
|
+
// Let's say you are parsing a message into message object m, and you want
|
409
|
+
// to take advantage of SetExtensionRegistry(). You must follow these
|
410
|
+
// requirements:
|
411
|
+
//
|
412
|
+
// The given DescriptorPool must contain m->GetDescriptor(). It is not
|
413
|
+
// sufficient for it to simply contain a descriptor that has the same name
|
414
|
+
// and content -- it must be the *exact object*. In other words:
|
415
|
+
// assert(pool->FindMessageTypeByName(m->GetDescriptor()->full_name()) ==
|
416
|
+
// m->GetDescriptor());
|
417
|
+
// There are two ways to satisfy this requirement:
|
418
|
+
// 1) Use m->GetDescriptor()->pool() as the pool. This is generally useless
|
419
|
+
// because this is the pool that would be used anyway if you didn't call
|
420
|
+
// SetExtensionRegistry() at all.
|
421
|
+
// 2) Use a DescriptorPool which has m->GetDescriptor()->pool() as an
|
422
|
+
// "underlay". Read the documentation for DescriptorPool for more
|
423
|
+
// information about underlays.
|
424
|
+
//
|
425
|
+
// You must also provide a MessageFactory. This factory will be used to
|
426
|
+
// construct Message objects representing extensions. The factory's
|
427
|
+
// GetPrototype() MUST return non-NULL for any Descriptor which can be found
|
428
|
+
// through the provided pool.
|
429
|
+
//
|
430
|
+
// If the provided factory might return instances of protocol-compiler-
|
431
|
+
// generated (i.e. compiled-in) types, or if the outer message object m is
|
432
|
+
// a generated type, then the given factory MUST have this property: If
|
433
|
+
// GetPrototype() is given a Descriptor which resides in
|
434
|
+
// DescriptorPool::generated_pool(), the factory MUST return the same
|
435
|
+
// prototype which MessageFactory::generated_factory() would return. That
|
436
|
+
// is, given a descriptor for a generated type, the factory must return an
|
437
|
+
// instance of the generated class (NOT DynamicMessage). However, when
|
438
|
+
// given a descriptor for a type that is NOT in generated_pool, the factory
|
439
|
+
// is free to return any implementation.
|
440
|
+
//
|
441
|
+
// The reason for this requirement is that generated sub-objects may be
|
442
|
+
// accessed via the standard (non-reflection) extension accessor methods,
|
443
|
+
// and these methods will down-cast the object to the generated class type.
|
444
|
+
// If the object is not actually of that type, the results would be undefined.
|
445
|
+
// On the other hand, if an extension is not compiled in, then there is no
|
446
|
+
// way the code could end up accessing it via the standard accessors -- the
|
447
|
+
// only way to access the extension is via reflection. When using reflection,
|
448
|
+
// DynamicMessage and generated messages are indistinguishable, so it's fine
|
449
|
+
// if these objects are represented using DynamicMessage.
|
450
|
+
//
|
451
|
+
// Using DynamicMessageFactory on which you have called
|
452
|
+
// SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the
|
453
|
+
// above requirement.
|
454
|
+
//
|
455
|
+
// If either pool or factory is NULL, both must be NULL.
|
456
|
+
//
|
457
|
+
// Note that this feature is ignored when parsing "lite" messages as they do
|
458
|
+
// not have descriptors.
|
459
|
+
void SetExtensionRegistry(const DescriptorPool* pool,
|
460
|
+
MessageFactory* factory);
|
461
|
+
|
462
|
+
// Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool
|
463
|
+
// has been provided.
|
464
|
+
const DescriptorPool* GetExtensionPool();
|
465
|
+
|
466
|
+
// Get the MessageFactory set via SetExtensionRegistry(), or NULL if no
|
467
|
+
// factory has been provided.
|
468
|
+
MessageFactory* GetExtensionFactory();
|
469
|
+
|
470
|
+
private:
|
471
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream);
|
472
|
+
|
473
|
+
ZeroCopyInputStream* input_;
|
474
|
+
const uint8* buffer_;
|
475
|
+
const uint8* buffer_end_; // pointer to the end of the buffer.
|
476
|
+
int total_bytes_read_; // total bytes read from input_, including
|
477
|
+
// the current buffer
|
478
|
+
|
479
|
+
// If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here
|
480
|
+
// so that we can BackUp() on destruction.
|
481
|
+
int overflow_bytes_;
|
482
|
+
|
483
|
+
// LastTagWas() stuff.
|
484
|
+
uint32 last_tag_; // result of last ReadTag() or ReadTagWithCutoff().
|
485
|
+
|
486
|
+
// This is set true by ReadTag{Fallback/Slow}() if it is called when exactly
|
487
|
+
// at EOF, or by ExpectAtEnd() when it returns true. This happens when we
|
488
|
+
// reach the end of a message and attempt to read another tag.
|
489
|
+
bool legitimate_message_end_;
|
490
|
+
|
491
|
+
// See EnableAliasing().
|
492
|
+
bool aliasing_enabled_;
|
493
|
+
|
494
|
+
// Limits
|
495
|
+
Limit current_limit_; // if position = -1, no limit is applied
|
496
|
+
|
497
|
+
// For simplicity, if the current buffer crosses a limit (either a normal
|
498
|
+
// limit created by PushLimit() or the total bytes limit), buffer_size_
|
499
|
+
// only tracks the number of bytes before that limit. This field
|
500
|
+
// contains the number of bytes after it. Note that this implies that if
|
501
|
+
// buffer_size_ == 0 and buffer_size_after_limit_ > 0, we know we've
|
502
|
+
// hit a limit. However, if both are zero, it doesn't necessarily mean
|
503
|
+
// we aren't at a limit -- the buffer may have ended exactly at the limit.
|
504
|
+
int buffer_size_after_limit_;
|
505
|
+
|
506
|
+
// Maximum number of bytes to read, period. This is unrelated to
|
507
|
+
// current_limit_. Set using SetTotalBytesLimit().
|
508
|
+
int total_bytes_limit_;
|
509
|
+
|
510
|
+
// If positive/0: Limit for bytes read after which a warning due to size
|
511
|
+
// should be logged.
|
512
|
+
// If -1: Printing of warning disabled. Can be set by client.
|
513
|
+
// If -2: Internal: Limit has been reached, print full size when destructing.
|
514
|
+
int total_bytes_warning_threshold_;
|
515
|
+
|
516
|
+
// Current recursion depth, controlled by IncrementRecursionDepth() and
|
517
|
+
// DecrementRecursionDepth().
|
518
|
+
int recursion_depth_;
|
519
|
+
// Recursion depth limit, set by SetRecursionLimit().
|
520
|
+
int recursion_limit_;
|
521
|
+
|
522
|
+
// See SetExtensionRegistry().
|
523
|
+
const DescriptorPool* extension_pool_;
|
524
|
+
MessageFactory* extension_factory_;
|
525
|
+
|
526
|
+
// Private member functions.
|
527
|
+
|
528
|
+
// Advance the buffer by a given number of bytes.
|
529
|
+
void Advance(int amount);
|
530
|
+
|
531
|
+
// Back up input_ to the current buffer position.
|
532
|
+
void BackUpInputToCurrentPosition();
|
533
|
+
|
534
|
+
// Recomputes the value of buffer_size_after_limit_. Must be called after
|
535
|
+
// current_limit_ or total_bytes_limit_ changes.
|
536
|
+
void RecomputeBufferLimits();
|
537
|
+
|
538
|
+
// Writes an error message saying that we hit total_bytes_limit_.
|
539
|
+
void PrintTotalBytesLimitError();
|
540
|
+
|
541
|
+
// Called when the buffer runs out to request more data. Implies an
|
542
|
+
// Advance(BufferSize()).
|
543
|
+
bool Refresh();
|
544
|
+
|
545
|
+
// When parsing varints, we optimize for the common case of small values, and
|
546
|
+
// then optimize for the case when the varint fits within the current buffer
|
547
|
+
// piece. The Fallback method is used when we can't use the one-byte
|
548
|
+
// optimization. The Slow method is yet another fallback when the buffer is
|
549
|
+
// not large enough. Making the slow path out-of-line speeds up the common
|
550
|
+
// case by 10-15%. The slow path is fairly uncommon: it only triggers when a
|
551
|
+
// message crosses multiple buffers.
|
552
|
+
bool ReadVarint32Fallback(uint32* value);
|
553
|
+
bool ReadVarint64Fallback(uint64* value);
|
554
|
+
bool ReadVarint32Slow(uint32* value);
|
555
|
+
bool ReadVarint64Slow(uint64* value);
|
556
|
+
bool ReadLittleEndian32Fallback(uint32* value);
|
557
|
+
bool ReadLittleEndian64Fallback(uint64* value);
|
558
|
+
// Fallback/slow methods for reading tags. These do not update last_tag_,
|
559
|
+
// but will set legitimate_message_end_ if we are at the end of the input
|
560
|
+
// stream.
|
561
|
+
uint32 ReadTagFallback();
|
562
|
+
uint32 ReadTagSlow();
|
563
|
+
bool ReadStringFallback(string* buffer, int size);
|
564
|
+
|
565
|
+
// Return the size of the buffer.
|
566
|
+
int BufferSize() const;
|
567
|
+
|
568
|
+
static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB
|
569
|
+
|
570
|
+
static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB
|
571
|
+
|
572
|
+
static int default_recursion_limit_; // 100 by default.
|
573
|
+
};
|
574
|
+
|
575
|
+
// Class which encodes and writes binary data which is composed of varint-
|
576
|
+
// encoded integers and fixed-width pieces. Wraps a ZeroCopyOutputStream.
|
577
|
+
// Most users will not need to deal with CodedOutputStream.
|
578
|
+
//
|
579
|
+
// Most methods of CodedOutputStream which return a bool return false if an
|
580
|
+
// underlying I/O error occurs. Once such a failure occurs, the
|
581
|
+
// CodedOutputStream is broken and is no longer useful. The Write* methods do
|
582
|
+
// not return the stream status, but will invalidate the stream if an error
|
583
|
+
// occurs. The client can probe HadError() to determine the status.
|
584
|
+
//
|
585
|
+
// Note that every method of CodedOutputStream which writes some data has
|
586
|
+
// a corresponding static "ToArray" version. These versions write directly
|
587
|
+
// to the provided buffer, returning a pointer past the last written byte.
|
588
|
+
// They require that the buffer has sufficient capacity for the encoded data.
|
589
|
+
// This allows an optimization where we check if an output stream has enough
|
590
|
+
// space for an entire message before we start writing and, if there is, we
|
591
|
+
// call only the ToArray methods to avoid doing bound checks for each
|
592
|
+
// individual value.
|
593
|
+
// i.e., in the example above:
|
594
|
+
//
|
595
|
+
// CodedOutputStream coded_output = new CodedOutputStream(raw_output);
|
596
|
+
// int magic_number = 1234;
|
597
|
+
// char text[] = "Hello world!";
|
598
|
+
//
|
599
|
+
// int coded_size = sizeof(magic_number) +
|
600
|
+
// CodedOutputStream::VarintSize32(strlen(text)) +
|
601
|
+
// strlen(text);
|
602
|
+
//
|
603
|
+
// uint8* buffer =
|
604
|
+
// coded_output->GetDirectBufferForNBytesAndAdvance(coded_size);
|
605
|
+
// if (buffer != NULL) {
|
606
|
+
// // The output stream has enough space in the buffer: write directly to
|
607
|
+
// // the array.
|
608
|
+
// buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number,
|
609
|
+
// buffer);
|
610
|
+
// buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer);
|
611
|
+
// buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer);
|
612
|
+
// } else {
|
613
|
+
// // Make bound-checked writes, which will ask the underlying stream for
|
614
|
+
// // more space as needed.
|
615
|
+
// coded_output->WriteLittleEndian32(magic_number);
|
616
|
+
// coded_output->WriteVarint32(strlen(text));
|
617
|
+
// coded_output->WriteRaw(text, strlen(text));
|
618
|
+
// }
|
619
|
+
//
|
620
|
+
// delete coded_output;
|
621
|
+
class LIBPROTOBUF_EXPORT CodedOutputStream {
|
622
|
+
public:
|
623
|
+
// Create an CodedOutputStream that writes to the given ZeroCopyOutputStream.
|
624
|
+
explicit CodedOutputStream(ZeroCopyOutputStream* output);
|
625
|
+
|
626
|
+
// Destroy the CodedOutputStream and position the underlying
|
627
|
+
// ZeroCopyOutputStream immediately after the last byte written.
|
628
|
+
~CodedOutputStream();
|
629
|
+
|
630
|
+
// Skips a number of bytes, leaving the bytes unmodified in the underlying
|
631
|
+
// buffer. Returns false if an underlying write error occurs. This is
|
632
|
+
// mainly useful with GetDirectBufferPointer().
|
633
|
+
bool Skip(int count);
|
634
|
+
|
635
|
+
// Sets *data to point directly at the unwritten part of the
|
636
|
+
// CodedOutputStream's underlying buffer, and *size to the size of that
|
637
|
+
// buffer, but does not advance the stream's current position. This will
|
638
|
+
// always either produce a non-empty buffer or return false. If the caller
|
639
|
+
// writes any data to this buffer, it should then call Skip() to skip over
|
640
|
+
// the consumed bytes. This may be useful for implementing external fast
|
641
|
+
// serialization routines for types of data not covered by the
|
642
|
+
// CodedOutputStream interface.
|
643
|
+
bool GetDirectBufferPointer(void** data, int* size);
|
644
|
+
|
645
|
+
// If there are at least "size" bytes available in the current buffer,
|
646
|
+
// returns a pointer directly into the buffer and advances over these bytes.
|
647
|
+
// The caller may then write directly into this buffer (e.g. using the
|
648
|
+
// *ToArray static methods) rather than go through CodedOutputStream. If
|
649
|
+
// there are not enough bytes available, returns NULL. The return pointer is
|
650
|
+
// invalidated as soon as any other non-const method of CodedOutputStream
|
651
|
+
// is called.
|
652
|
+
inline uint8* GetDirectBufferForNBytesAndAdvance(int size);
|
653
|
+
|
654
|
+
// Write raw bytes, copying them from the given buffer.
|
655
|
+
void WriteRaw(const void* buffer, int size);
|
656
|
+
// Like WriteRaw() but will try to write aliased data if aliasing is
|
657
|
+
// turned on.
|
658
|
+
void WriteRawMaybeAliased(const void* data, int size);
|
659
|
+
// Like WriteRaw() but writing directly to the target array.
|
660
|
+
// This is _not_ inlined, as the compiler often optimizes memcpy into inline
|
661
|
+
// copy loops. Since this gets called by every field with string or bytes
|
662
|
+
// type, inlining may lead to a significant amount of code bloat, with only a
|
663
|
+
// minor performance gain.
|
664
|
+
static uint8* WriteRawToArray(const void* buffer, int size, uint8* target);
|
665
|
+
|
666
|
+
// Equivalent to WriteRaw(str.data(), str.size()).
|
667
|
+
void WriteString(const string& str);
|
668
|
+
// Like WriteString() but writing directly to the target array.
|
669
|
+
static uint8* WriteStringToArray(const string& str, uint8* target);
|
670
|
+
// Write the varint-encoded size of str followed by str.
|
671
|
+
static uint8* WriteStringWithSizeToArray(const string& str, uint8* target);
|
672
|
+
|
673
|
+
|
674
|
+
// Instructs the CodedOutputStream to allow the underlying
|
675
|
+
// ZeroCopyOutputStream to hold pointers to the original structure instead of
|
676
|
+
// copying, if it supports it (i.e. output->AllowsAliasing() is true). If the
|
677
|
+
// underlying stream does not support aliasing, then enabling it has no
|
678
|
+
// affect. For now, this only affects the behavior of
|
679
|
+
// WriteRawMaybeAliased().
|
680
|
+
//
|
681
|
+
// NOTE: It is caller's responsibility to ensure that the chunk of memory
|
682
|
+
// remains live until all of the data has been consumed from the stream.
|
683
|
+
void EnableAliasing(bool enabled);
|
684
|
+
|
685
|
+
// Write a 32-bit little-endian integer.
|
686
|
+
void WriteLittleEndian32(uint32 value);
|
687
|
+
// Like WriteLittleEndian32() but writing directly to the target array.
|
688
|
+
static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target);
|
689
|
+
// Write a 64-bit little-endian integer.
|
690
|
+
void WriteLittleEndian64(uint64 value);
|
691
|
+
// Like WriteLittleEndian64() but writing directly to the target array.
|
692
|
+
static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target);
|
693
|
+
|
694
|
+
// Write an unsigned integer with Varint encoding. Writing a 32-bit value
|
695
|
+
// is equivalent to casting it to uint64 and writing it as a 64-bit value,
|
696
|
+
// but may be more efficient.
|
697
|
+
void WriteVarint32(uint32 value);
|
698
|
+
// Like WriteVarint32() but writing directly to the target array.
|
699
|
+
static uint8* WriteVarint32ToArray(uint32 value, uint8* target);
|
700
|
+
// Write an unsigned integer with Varint encoding.
|
701
|
+
void WriteVarint64(uint64 value);
|
702
|
+
// Like WriteVarint64() but writing directly to the target array.
|
703
|
+
static uint8* WriteVarint64ToArray(uint64 value, uint8* target);
|
704
|
+
|
705
|
+
// Equivalent to WriteVarint32() except when the value is negative,
|
706
|
+
// in which case it must be sign-extended to a full 10 bytes.
|
707
|
+
void WriteVarint32SignExtended(int32 value);
|
708
|
+
// Like WriteVarint32SignExtended() but writing directly to the target array.
|
709
|
+
static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target);
|
710
|
+
|
711
|
+
// This is identical to WriteVarint32(), but optimized for writing tags.
|
712
|
+
// In particular, if the input is a compile-time constant, this method
|
713
|
+
// compiles down to a couple instructions.
|
714
|
+
// Always inline because otherwise the aformentioned optimization can't work,
|
715
|
+
// but GCC by default doesn't want to inline this.
|
716
|
+
void WriteTag(uint32 value);
|
717
|
+
// Like WriteTag() but writing directly to the target array.
|
718
|
+
static uint8* WriteTagToArray(
|
719
|
+
uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
720
|
+
|
721
|
+
// Returns the number of bytes needed to encode the given value as a varint.
|
722
|
+
static int VarintSize32(uint32 value);
|
723
|
+
// Returns the number of bytes needed to encode the given value as a varint.
|
724
|
+
static int VarintSize64(uint64 value);
|
725
|
+
|
726
|
+
// If negative, 10 bytes. Otheriwse, same as VarintSize32().
|
727
|
+
static int VarintSize32SignExtended(int32 value);
|
728
|
+
|
729
|
+
// Compile-time equivalent of VarintSize32().
|
730
|
+
template <uint32 Value>
|
731
|
+
struct StaticVarintSize32 {
|
732
|
+
static const int value =
|
733
|
+
(Value < (1 << 7))
|
734
|
+
? 1
|
735
|
+
: (Value < (1 << 14))
|
736
|
+
? 2
|
737
|
+
: (Value < (1 << 21))
|
738
|
+
? 3
|
739
|
+
: (Value < (1 << 28))
|
740
|
+
? 4
|
741
|
+
: 5;
|
742
|
+
};
|
743
|
+
|
744
|
+
// Returns the total number of bytes written since this object was created.
|
745
|
+
inline int ByteCount() const;
|
746
|
+
|
747
|
+
// Returns true if there was an underlying I/O error since this object was
|
748
|
+
// created.
|
749
|
+
bool HadError() const { return had_error_; }
|
750
|
+
|
751
|
+
private:
|
752
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream);
|
753
|
+
|
754
|
+
ZeroCopyOutputStream* output_;
|
755
|
+
uint8* buffer_;
|
756
|
+
int buffer_size_;
|
757
|
+
int total_bytes_; // Sum of sizes of all buffers seen so far.
|
758
|
+
bool had_error_; // Whether an error occurred during output.
|
759
|
+
bool aliasing_enabled_; // See EnableAliasing().
|
760
|
+
|
761
|
+
// Advance the buffer by a given number of bytes.
|
762
|
+
void Advance(int amount);
|
763
|
+
|
764
|
+
// Called when the buffer runs out to request more data. Implies an
|
765
|
+
// Advance(buffer_size_).
|
766
|
+
bool Refresh();
|
767
|
+
|
768
|
+
// Like WriteRaw() but may avoid copying if the underlying
|
769
|
+
// ZeroCopyOutputStream supports it.
|
770
|
+
void WriteAliasedRaw(const void* buffer, int size);
|
771
|
+
|
772
|
+
static uint8* WriteVarint32FallbackToArray(uint32 value, uint8* target);
|
773
|
+
|
774
|
+
// Always-inlined versions of WriteVarint* functions so that code can be
|
775
|
+
// reused, while still controlling size. For instance, WriteVarint32ToArray()
|
776
|
+
// should not directly call this: since it is inlined itself, doing so
|
777
|
+
// would greatly increase the size of generated code. Instead, it should call
|
778
|
+
// WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already
|
779
|
+
// out-of-line, so it should just invoke this directly to avoid any extra
|
780
|
+
// function call overhead.
|
781
|
+
static uint8* WriteVarint32FallbackToArrayInline(
|
782
|
+
uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
783
|
+
static uint8* WriteVarint64ToArrayInline(
|
784
|
+
uint64 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
785
|
+
|
786
|
+
static int VarintSize32Fallback(uint32 value);
|
787
|
+
};
|
788
|
+
|
789
|
+
// inline methods ====================================================
|
790
|
+
// The vast majority of varints are only one byte. These inline
|
791
|
+
// methods optimize for that case.
|
792
|
+
|
793
|
+
inline bool CodedInputStream::ReadVarint32(uint32* value) {
|
794
|
+
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) {
|
795
|
+
*value = *buffer_;
|
796
|
+
Advance(1);
|
797
|
+
return true;
|
798
|
+
} else {
|
799
|
+
return ReadVarint32Fallback(value);
|
800
|
+
}
|
801
|
+
}
|
802
|
+
|
803
|
+
inline bool CodedInputStream::ReadVarint64(uint64* value) {
|
804
|
+
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) {
|
805
|
+
*value = *buffer_;
|
806
|
+
Advance(1);
|
807
|
+
return true;
|
808
|
+
} else {
|
809
|
+
return ReadVarint64Fallback(value);
|
810
|
+
}
|
811
|
+
}
|
812
|
+
|
813
|
+
// static
|
814
|
+
inline const uint8* CodedInputStream::ReadLittleEndian32FromArray(
|
815
|
+
const uint8* buffer,
|
816
|
+
uint32* value) {
|
817
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
818
|
+
memcpy(value, buffer, sizeof(*value));
|
819
|
+
return buffer + sizeof(*value);
|
820
|
+
#else
|
821
|
+
*value = (static_cast<uint32>(buffer[0]) ) |
|
822
|
+
(static_cast<uint32>(buffer[1]) << 8) |
|
823
|
+
(static_cast<uint32>(buffer[2]) << 16) |
|
824
|
+
(static_cast<uint32>(buffer[3]) << 24);
|
825
|
+
return buffer + sizeof(*value);
|
826
|
+
#endif
|
827
|
+
}
|
828
|
+
// static
|
829
|
+
inline const uint8* CodedInputStream::ReadLittleEndian64FromArray(
|
830
|
+
const uint8* buffer,
|
831
|
+
uint64* value) {
|
832
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
833
|
+
memcpy(value, buffer, sizeof(*value));
|
834
|
+
return buffer + sizeof(*value);
|
835
|
+
#else
|
836
|
+
uint32 part0 = (static_cast<uint32>(buffer[0]) ) |
|
837
|
+
(static_cast<uint32>(buffer[1]) << 8) |
|
838
|
+
(static_cast<uint32>(buffer[2]) << 16) |
|
839
|
+
(static_cast<uint32>(buffer[3]) << 24);
|
840
|
+
uint32 part1 = (static_cast<uint32>(buffer[4]) ) |
|
841
|
+
(static_cast<uint32>(buffer[5]) << 8) |
|
842
|
+
(static_cast<uint32>(buffer[6]) << 16) |
|
843
|
+
(static_cast<uint32>(buffer[7]) << 24);
|
844
|
+
*value = static_cast<uint64>(part0) |
|
845
|
+
(static_cast<uint64>(part1) << 32);
|
846
|
+
return buffer + sizeof(*value);
|
847
|
+
#endif
|
848
|
+
}
|
849
|
+
|
850
|
+
inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
|
851
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
852
|
+
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
|
853
|
+
memcpy(value, buffer_, sizeof(*value));
|
854
|
+
Advance(sizeof(*value));
|
855
|
+
return true;
|
856
|
+
} else {
|
857
|
+
return ReadLittleEndian32Fallback(value);
|
858
|
+
}
|
859
|
+
#else
|
860
|
+
return ReadLittleEndian32Fallback(value);
|
861
|
+
#endif
|
862
|
+
}
|
863
|
+
|
864
|
+
inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
|
865
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
866
|
+
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
|
867
|
+
memcpy(value, buffer_, sizeof(*value));
|
868
|
+
Advance(sizeof(*value));
|
869
|
+
return true;
|
870
|
+
} else {
|
871
|
+
return ReadLittleEndian64Fallback(value);
|
872
|
+
}
|
873
|
+
#else
|
874
|
+
return ReadLittleEndian64Fallback(value);
|
875
|
+
#endif
|
876
|
+
}
|
877
|
+
|
878
|
+
inline uint32 CodedInputStream::ReadTag() {
|
879
|
+
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] < 0x80) {
|
880
|
+
last_tag_ = buffer_[0];
|
881
|
+
Advance(1);
|
882
|
+
return last_tag_;
|
883
|
+
} else {
|
884
|
+
last_tag_ = ReadTagFallback();
|
885
|
+
return last_tag_;
|
886
|
+
}
|
887
|
+
}
|
888
|
+
|
889
|
+
inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
|
890
|
+
uint32 cutoff) {
|
891
|
+
// In performance-sensitive code we can expect cutoff to be a compile-time
|
892
|
+
// constant, and things like "cutoff >= kMax1ByteVarint" to be evaluated at
|
893
|
+
// compile time.
|
894
|
+
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) {
|
895
|
+
// Hot case: buffer_ non_empty, buffer_[0] in [1, 128).
|
896
|
+
// TODO(gpike): Is it worth rearranging this? E.g., if the number of fields
|
897
|
+
// is large enough then is it better to check for the two-byte case first?
|
898
|
+
if (static_cast<int8>(buffer_[0]) > 0) {
|
899
|
+
const uint32 kMax1ByteVarint = 0x7f;
|
900
|
+
uint32 tag = last_tag_ = buffer_[0];
|
901
|
+
Advance(1);
|
902
|
+
return make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff);
|
903
|
+
}
|
904
|
+
// Other hot case: cutoff >= 0x80, buffer_ has at least two bytes available,
|
905
|
+
// and tag is two bytes. The latter is tested by bitwise-and-not of the
|
906
|
+
// first byte and the second byte.
|
907
|
+
if (cutoff >= 0x80 &&
|
908
|
+
GOOGLE_PREDICT_TRUE(buffer_ + 1 < buffer_end_) &&
|
909
|
+
GOOGLE_PREDICT_TRUE((buffer_[0] & ~buffer_[1]) >= 0x80)) {
|
910
|
+
const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f;
|
911
|
+
uint32 tag = last_tag_ = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80);
|
912
|
+
Advance(2);
|
913
|
+
// It might make sense to test for tag == 0 now, but it is so rare that
|
914
|
+
// that we don't bother. A varint-encoded 0 should be one byte unless
|
915
|
+
// the encoder lost its mind. The second part of the return value of
|
916
|
+
// this function is allowed to be either true or false if the tag is 0,
|
917
|
+
// so we don't have to check for tag == 0. We may need to check whether
|
918
|
+
// it exceeds cutoff.
|
919
|
+
bool at_or_below_cutoff = cutoff >= kMax2ByteVarint || tag <= cutoff;
|
920
|
+
return make_pair(tag, at_or_below_cutoff);
|
921
|
+
}
|
922
|
+
}
|
923
|
+
// Slow path
|
924
|
+
last_tag_ = ReadTagFallback();
|
925
|
+
return make_pair(last_tag_, static_cast<uint32>(last_tag_ - 1) < cutoff);
|
926
|
+
}
|
927
|
+
|
928
|
+
inline bool CodedInputStream::LastTagWas(uint32 expected) {
|
929
|
+
return last_tag_ == expected;
|
930
|
+
}
|
931
|
+
|
932
|
+
inline bool CodedInputStream::ConsumedEntireMessage() {
|
933
|
+
return legitimate_message_end_;
|
934
|
+
}
|
935
|
+
|
936
|
+
inline bool CodedInputStream::ExpectTag(uint32 expected) {
|
937
|
+
if (expected < (1 << 7)) {
|
938
|
+
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] == expected) {
|
939
|
+
Advance(1);
|
940
|
+
return true;
|
941
|
+
} else {
|
942
|
+
return false;
|
943
|
+
}
|
944
|
+
} else if (expected < (1 << 14)) {
|
945
|
+
if (GOOGLE_PREDICT_TRUE(BufferSize() >= 2) &&
|
946
|
+
buffer_[0] == static_cast<uint8>(expected | 0x80) &&
|
947
|
+
buffer_[1] == static_cast<uint8>(expected >> 7)) {
|
948
|
+
Advance(2);
|
949
|
+
return true;
|
950
|
+
} else {
|
951
|
+
return false;
|
952
|
+
}
|
953
|
+
} else {
|
954
|
+
// Don't bother optimizing for larger values.
|
955
|
+
return false;
|
956
|
+
}
|
957
|
+
}
|
958
|
+
|
959
|
+
inline const uint8* CodedInputStream::ExpectTagFromArray(
|
960
|
+
const uint8* buffer, uint32 expected) {
|
961
|
+
if (expected < (1 << 7)) {
|
962
|
+
if (buffer[0] == expected) {
|
963
|
+
return buffer + 1;
|
964
|
+
}
|
965
|
+
} else if (expected < (1 << 14)) {
|
966
|
+
if (buffer[0] == static_cast<uint8>(expected | 0x80) &&
|
967
|
+
buffer[1] == static_cast<uint8>(expected >> 7)) {
|
968
|
+
return buffer + 2;
|
969
|
+
}
|
970
|
+
}
|
971
|
+
return NULL;
|
972
|
+
}
|
973
|
+
|
974
|
+
inline void CodedInputStream::GetDirectBufferPointerInline(const void** data,
|
975
|
+
int* size) {
|
976
|
+
*data = buffer_;
|
977
|
+
*size = buffer_end_ - buffer_;
|
978
|
+
}
|
979
|
+
|
980
|
+
inline bool CodedInputStream::ExpectAtEnd() {
|
981
|
+
// If we are at a limit we know no more bytes can be read. Otherwise, it's
|
982
|
+
// hard to say without calling Refresh(), and we'd rather not do that.
|
983
|
+
|
984
|
+
if (buffer_ == buffer_end_ &&
|
985
|
+
((buffer_size_after_limit_ != 0) ||
|
986
|
+
(total_bytes_read_ == current_limit_))) {
|
987
|
+
last_tag_ = 0; // Pretend we called ReadTag()...
|
988
|
+
legitimate_message_end_ = true; // ... and it hit EOF.
|
989
|
+
return true;
|
990
|
+
} else {
|
991
|
+
return false;
|
992
|
+
}
|
993
|
+
}
|
994
|
+
|
995
|
+
inline int CodedInputStream::CurrentPosition() const {
|
996
|
+
return total_bytes_read_ - (BufferSize() + buffer_size_after_limit_);
|
997
|
+
}
|
998
|
+
|
999
|
+
inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) {
|
1000
|
+
if (buffer_size_ < size) {
|
1001
|
+
return NULL;
|
1002
|
+
} else {
|
1003
|
+
uint8* result = buffer_;
|
1004
|
+
Advance(size);
|
1005
|
+
return result;
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value,
|
1010
|
+
uint8* target) {
|
1011
|
+
if (value < 0x80) {
|
1012
|
+
*target = value;
|
1013
|
+
return target + 1;
|
1014
|
+
} else {
|
1015
|
+
return WriteVarint32FallbackToArray(value, target);
|
1016
|
+
}
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
|
1020
|
+
if (value < 0) {
|
1021
|
+
WriteVarint64(static_cast<uint64>(value));
|
1022
|
+
} else {
|
1023
|
+
WriteVarint32(static_cast<uint32>(value));
|
1024
|
+
}
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray(
|
1028
|
+
int32 value, uint8* target) {
|
1029
|
+
if (value < 0) {
|
1030
|
+
return WriteVarint64ToArray(static_cast<uint64>(value), target);
|
1031
|
+
} else {
|
1032
|
+
return WriteVarint32ToArray(static_cast<uint32>(value), target);
|
1033
|
+
}
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value,
|
1037
|
+
uint8* target) {
|
1038
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
1039
|
+
memcpy(target, &value, sizeof(value));
|
1040
|
+
#else
|
1041
|
+
target[0] = static_cast<uint8>(value);
|
1042
|
+
target[1] = static_cast<uint8>(value >> 8);
|
1043
|
+
target[2] = static_cast<uint8>(value >> 16);
|
1044
|
+
target[3] = static_cast<uint8>(value >> 24);
|
1045
|
+
#endif
|
1046
|
+
return target + sizeof(value);
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value,
|
1050
|
+
uint8* target) {
|
1051
|
+
#if defined(PROTOBUF_LITTLE_ENDIAN)
|
1052
|
+
memcpy(target, &value, sizeof(value));
|
1053
|
+
#else
|
1054
|
+
uint32 part0 = static_cast<uint32>(value);
|
1055
|
+
uint32 part1 = static_cast<uint32>(value >> 32);
|
1056
|
+
|
1057
|
+
target[0] = static_cast<uint8>(part0);
|
1058
|
+
target[1] = static_cast<uint8>(part0 >> 8);
|
1059
|
+
target[2] = static_cast<uint8>(part0 >> 16);
|
1060
|
+
target[3] = static_cast<uint8>(part0 >> 24);
|
1061
|
+
target[4] = static_cast<uint8>(part1);
|
1062
|
+
target[5] = static_cast<uint8>(part1 >> 8);
|
1063
|
+
target[6] = static_cast<uint8>(part1 >> 16);
|
1064
|
+
target[7] = static_cast<uint8>(part1 >> 24);
|
1065
|
+
#endif
|
1066
|
+
return target + sizeof(value);
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
inline void CodedOutputStream::WriteTag(uint32 value) {
|
1070
|
+
WriteVarint32(value);
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
inline uint8* CodedOutputStream::WriteTagToArray(
|
1074
|
+
uint32 value, uint8* target) {
|
1075
|
+
if (value < (1 << 7)) {
|
1076
|
+
target[0] = value;
|
1077
|
+
return target + 1;
|
1078
|
+
} else if (value < (1 << 14)) {
|
1079
|
+
target[0] = static_cast<uint8>(value | 0x80);
|
1080
|
+
target[1] = static_cast<uint8>(value >> 7);
|
1081
|
+
return target + 2;
|
1082
|
+
} else {
|
1083
|
+
return WriteVarint32FallbackToArray(value, target);
|
1084
|
+
}
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
inline int CodedOutputStream::VarintSize32(uint32 value) {
|
1088
|
+
if (value < (1 << 7)) {
|
1089
|
+
return 1;
|
1090
|
+
} else {
|
1091
|
+
return VarintSize32Fallback(value);
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
inline int CodedOutputStream::VarintSize32SignExtended(int32 value) {
|
1096
|
+
if (value < 0) {
|
1097
|
+
return 10; // TODO(kenton): Make this a symbolic constant.
|
1098
|
+
} else {
|
1099
|
+
return VarintSize32(static_cast<uint32>(value));
|
1100
|
+
}
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
inline void CodedOutputStream::WriteString(const string& str) {
|
1104
|
+
WriteRaw(str.data(), static_cast<int>(str.size()));
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
inline void CodedOutputStream::WriteRawMaybeAliased(
|
1108
|
+
const void* data, int size) {
|
1109
|
+
if (aliasing_enabled_) {
|
1110
|
+
WriteAliasedRaw(data, size);
|
1111
|
+
} else {
|
1112
|
+
WriteRaw(data, size);
|
1113
|
+
}
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
inline uint8* CodedOutputStream::WriteStringToArray(
|
1117
|
+
const string& str, uint8* target) {
|
1118
|
+
return WriteRawToArray(str.data(), static_cast<int>(str.size()), target);
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
inline int CodedOutputStream::ByteCount() const {
|
1122
|
+
return total_bytes_ - buffer_size_;
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
inline void CodedInputStream::Advance(int amount) {
|
1126
|
+
buffer_ += amount;
|
1127
|
+
}
|
1128
|
+
|
1129
|
+
inline void CodedOutputStream::Advance(int amount) {
|
1130
|
+
buffer_ += amount;
|
1131
|
+
buffer_size_ -= amount;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
inline void CodedInputStream::SetRecursionLimit(int limit) {
|
1135
|
+
recursion_limit_ = limit;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
inline bool CodedInputStream::IncrementRecursionDepth() {
|
1139
|
+
++recursion_depth_;
|
1140
|
+
return recursion_depth_ <= recursion_limit_;
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
inline void CodedInputStream::DecrementRecursionDepth() {
|
1144
|
+
if (recursion_depth_ > 0) --recursion_depth_;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
inline void CodedInputStream::SetExtensionRegistry(const DescriptorPool* pool,
|
1148
|
+
MessageFactory* factory) {
|
1149
|
+
extension_pool_ = pool;
|
1150
|
+
extension_factory_ = factory;
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
inline const DescriptorPool* CodedInputStream::GetExtensionPool() {
|
1154
|
+
return extension_pool_;
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
inline MessageFactory* CodedInputStream::GetExtensionFactory() {
|
1158
|
+
return extension_factory_;
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
inline int CodedInputStream::BufferSize() const {
|
1162
|
+
return buffer_end_ - buffer_;
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input)
|
1166
|
+
: input_(input),
|
1167
|
+
buffer_(NULL),
|
1168
|
+
buffer_end_(NULL),
|
1169
|
+
total_bytes_read_(0),
|
1170
|
+
overflow_bytes_(0),
|
1171
|
+
last_tag_(0),
|
1172
|
+
legitimate_message_end_(false),
|
1173
|
+
aliasing_enabled_(false),
|
1174
|
+
current_limit_(kint32max),
|
1175
|
+
buffer_size_after_limit_(0),
|
1176
|
+
total_bytes_limit_(kDefaultTotalBytesLimit),
|
1177
|
+
total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
|
1178
|
+
recursion_depth_(0),
|
1179
|
+
recursion_limit_(default_recursion_limit_),
|
1180
|
+
extension_pool_(NULL),
|
1181
|
+
extension_factory_(NULL) {
|
1182
|
+
// Eagerly Refresh() so buffer space is immediately available.
|
1183
|
+
Refresh();
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
inline CodedInputStream::CodedInputStream(const uint8* buffer, int size)
|
1187
|
+
: input_(NULL),
|
1188
|
+
buffer_(buffer),
|
1189
|
+
buffer_end_(buffer + size),
|
1190
|
+
total_bytes_read_(size),
|
1191
|
+
overflow_bytes_(0),
|
1192
|
+
last_tag_(0),
|
1193
|
+
legitimate_message_end_(false),
|
1194
|
+
aliasing_enabled_(false),
|
1195
|
+
current_limit_(size),
|
1196
|
+
buffer_size_after_limit_(0),
|
1197
|
+
total_bytes_limit_(kDefaultTotalBytesLimit),
|
1198
|
+
total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
|
1199
|
+
recursion_depth_(0),
|
1200
|
+
recursion_limit_(default_recursion_limit_),
|
1201
|
+
extension_pool_(NULL),
|
1202
|
+
extension_factory_(NULL) {
|
1203
|
+
// Note that setting current_limit_ == size is important to prevent some
|
1204
|
+
// code paths from trying to access input_ and segfaulting.
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
inline bool CodedInputStream::IsFlat() const {
|
1208
|
+
return input_ == NULL;
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
} // namespace io
|
1212
|
+
} // namespace protobuf
|
1213
|
+
|
1214
|
+
|
1215
|
+
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
1216
|
+
#pragma runtime_checks("c", restore)
|
1217
|
+
#endif // _MSC_VER
|
1218
|
+
|
1219
|
+
} // namespace google
|
1220
|
+
#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
|