protobuf 2.2.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/.yardopts +5 -0
- data/Gemfile +3 -0
- data/README.md +316 -0
- data/Rakefile +29 -0
- data/UPGRADING.md +60 -0
- data/bin/rpc_server +5 -0
- data/bin/rprotoc +62 -0
- data/examples/addressbook.pb.rb +55 -0
- data/examples/addressbook.proto +24 -0
- data/examples/reading_a_message.rb +32 -0
- data/examples/writing_a_message.rb +46 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
- data/ext/ruby_generator/Makefile +10 -0
- data/ext/ruby_generator/RubyGenerator.cpp +450 -0
- data/ext/ruby_generator/RubyGenerator.h +199 -0
- data/ext/ruby_generator/extconf.rb +36 -0
- data/ext/ruby_generator/protoc-ruby +0 -0
- data/lib/protobuf/cli.rb +188 -0
- data/lib/protobuf/enum.rb +58 -0
- data/lib/protobuf/enum_value.rb +59 -0
- data/lib/protobuf/evented.rb +22 -0
- data/lib/protobuf/exceptions.rb +11 -0
- data/lib/protobuf/ext/eventmachine.rb +14 -0
- data/lib/protobuf/field/base_field.rb +240 -0
- data/lib/protobuf/field/bool_field.rb +36 -0
- data/lib/protobuf/field/bytes_field.rb +38 -0
- data/lib/protobuf/field/double_field.rb +19 -0
- data/lib/protobuf/field/enum_field.rb +50 -0
- data/lib/protobuf/field/extension_fields.rb +32 -0
- data/lib/protobuf/field/field_array.rb +65 -0
- data/lib/protobuf/field/fixed32_field.rb +19 -0
- data/lib/protobuf/field/fixed64_field.rb +22 -0
- data/lib/protobuf/field/float_field.rb +31 -0
- data/lib/protobuf/field/int32_field.rb +12 -0
- data/lib/protobuf/field/int64_field.rb +12 -0
- data/lib/protobuf/field/integer_field.rb +19 -0
- data/lib/protobuf/field/message_field.rb +53 -0
- data/lib/protobuf/field/sfixed32_field.rb +21 -0
- data/lib/protobuf/field/sfixed64_field.rb +24 -0
- data/lib/protobuf/field/signed_integer_field.rb +23 -0
- data/lib/protobuf/field/sint32_field.rb +12 -0
- data/lib/protobuf/field/sint64_field.rb +12 -0
- data/lib/protobuf/field/string_field.rb +14 -0
- data/lib/protobuf/field/uint32_field.rb +12 -0
- data/lib/protobuf/field/uint64_field.rb +12 -0
- data/lib/protobuf/field/varint_field.rb +61 -0
- data/lib/protobuf/field.rb +57 -0
- data/lib/protobuf/logger.rb +86 -0
- data/lib/protobuf/message/decoder.rb +83 -0
- data/lib/protobuf/message/encoder.rb +48 -0
- data/lib/protobuf/message/extend.rb +8 -0
- data/lib/protobuf/message/message.rb +1 -0
- data/lib/protobuf/message.rb +320 -0
- data/lib/protobuf/rpc/buffer.rb +79 -0
- data/lib/protobuf/rpc/client.rb +166 -0
- data/lib/protobuf/rpc/connector.rb +19 -0
- data/lib/protobuf/rpc/connectors/base.rb +38 -0
- data/lib/protobuf/rpc/connectors/common.rb +156 -0
- data/lib/protobuf/rpc/connectors/em_client.rb +84 -0
- data/lib/protobuf/rpc/connectors/eventmachine.rb +87 -0
- data/lib/protobuf/rpc/connectors/socket.rb +73 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +69 -0
- data/lib/protobuf/rpc/error/client_error.rb +31 -0
- data/lib/protobuf/rpc/error/server_error.rb +43 -0
- data/lib/protobuf/rpc/error.rb +25 -0
- data/lib/protobuf/rpc/rpc.pb.rb +118 -0
- data/lib/protobuf/rpc/server.rb +89 -0
- data/lib/protobuf/rpc/servers/evented/server.rb +41 -0
- data/lib/protobuf/rpc/servers/evented_runner.rb +21 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +111 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +66 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +27 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +87 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +50 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +27 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +60 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +25 -0
- data/lib/protobuf/rpc/service.rb +173 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +130 -0
- data/lib/protobuf/rpc/service_filters.rb +267 -0
- data/lib/protobuf/rpc/stat.rb +83 -0
- data/lib/protobuf/socket.rb +22 -0
- data/lib/protobuf/version.rb +4 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/lib/protobuf.rb +86 -0
- data/proto/rpc.pb.rb +48 -0
- data/proto/rpc.proto +73 -0
- data/protobuf.gemspec +44 -0
- data/spec/benchmark/tasks.rb +179 -0
- data/spec/functional/embedded_service_spec.rb +7 -0
- data/spec/functional/evented_server_spec.rb +64 -0
- data/spec/functional/socket_server_spec.rb +58 -0
- data/spec/functional/zmq_server_spec.rb +58 -0
- data/spec/lib/protobuf/cli_spec.rb +212 -0
- data/spec/lib/protobuf/enum_spec.rb +98 -0
- data/spec/lib/protobuf/enum_value_spec.rb +15 -0
- data/spec/lib/protobuf/logger_spec.rb +131 -0
- data/spec/lib/protobuf/message/encoder_spec.rb +19 -0
- data/spec/lib/protobuf/message_spec.rb +209 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +158 -0
- data/spec/lib/protobuf/rpc/connector_spec.rb +32 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +128 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +36 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +22 -0
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +18 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +43 -0
- data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +45 -0
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +44 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +116 -0
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +451 -0
- data/spec/lib/protobuf/rpc/service_spec.rb +165 -0
- data/spec/lib/protobuf_spec.rb +62 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/server.rb +101 -0
- data/spec/support/test/enum.pb.rb +34 -0
- data/spec/support/test/enum.proto +12 -0
- data/spec/support/test/resource.pb.rb +58 -0
- data/spec/support/test/resource.proto +31 -0
- data/spec/support/test/resource_service.rb +14 -0
- data/spec/support/test_app_file.rb +2 -0
- data/spec/support/tolerance_matcher.rb +40 -0
- data/test/data/data.bin +3 -0
- data/test/data/data_source.py +14 -0
- data/test/data/types.bin +0 -0
- data/test/data/types_source.py +22 -0
- data/test/data/unk.png +0 -0
- data/test/proto/addressbook.pb.rb +66 -0
- data/test/proto/addressbook.proto +33 -0
- data/test/proto/addressbook_base.pb.rb +58 -0
- data/test/proto/addressbook_base.proto +26 -0
- data/test/proto/addressbook_ext.pb.rb +20 -0
- data/test/proto/addressbook_ext.proto +6 -0
- data/test/proto/collision.pb.rb +17 -0
- data/test/proto/collision.proto +5 -0
- data/test/proto/ext_collision.pb.rb +24 -0
- data/test/proto/ext_collision.proto +8 -0
- data/test/proto/ext_range.pb.rb +22 -0
- data/test/proto/ext_range.proto +7 -0
- data/test/proto/float_default.proto +10 -0
- data/test/proto/lowercase.pb.rb +30 -0
- data/test/proto/lowercase.proto +9 -0
- data/test/proto/merge.pb.rb +39 -0
- data/test/proto/merge.proto +15 -0
- data/test/proto/nested.pb.rb +30 -0
- data/test/proto/nested.proto +9 -0
- data/test/proto/optional_field.pb.rb +35 -0
- data/test/proto/optional_field.proto +12 -0
- data/test/proto/packed.pb.rb +22 -0
- data/test/proto/packed.proto +6 -0
- data/test/proto/rpc.proto +6 -0
- data/test/proto/types.pb.rb +84 -0
- data/test/proto/types.proto +37 -0
- data/test/test_addressbook.rb +56 -0
- data/test/test_enum_value.rb +41 -0
- data/test/test_extension.rb +36 -0
- data/test/test_lowercase.rb +11 -0
- data/test/test_message.rb +128 -0
- data/test/test_optional_field.rb +103 -0
- data/test/test_packed_field.rb +40 -0
- data/test/test_parse.rb +15 -0
- data/test/test_repeated_types.rb +132 -0
- data/test/test_serialize.rb +61 -0
- data/test/test_standard_message.rb +96 -0
- data/test/test_types.rb +226 -0
- metadata +461 -0
@@ -0,0 +1,774 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2008 Google Inc. All rights reserved.
|
3
|
+
// http://code.google.com/p/protobuf/
|
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
|
+
// wink@google.com (Wink Saville) (refactored from wire_format.h)
|
33
|
+
// Based on original Protocol Buffers design by
|
34
|
+
// Sanjay Ghemawat, Jeff Dean, and others.
|
35
|
+
|
36
|
+
#ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
|
37
|
+
#define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
|
38
|
+
|
39
|
+
#include <string>
|
40
|
+
#include <google/protobuf/stubs/common.h>
|
41
|
+
#include <google/protobuf/message_lite.h>
|
42
|
+
#include <google/protobuf/repeated_field.h>
|
43
|
+
#include <google/protobuf/wire_format_lite.h>
|
44
|
+
#include <google/protobuf/generated_message_util.h>
|
45
|
+
#include <google/protobuf/io/coded_stream.h>
|
46
|
+
|
47
|
+
|
48
|
+
namespace google {
|
49
|
+
namespace protobuf {
|
50
|
+
namespace internal {
|
51
|
+
|
52
|
+
// Implementation details of ReadPrimitive.
|
53
|
+
|
54
|
+
template <>
|
55
|
+
inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_INT32>(
|
56
|
+
io::CodedInputStream* input,
|
57
|
+
int32* value) {
|
58
|
+
uint32 temp;
|
59
|
+
if (!input->ReadVarint32(&temp)) return false;
|
60
|
+
*value = static_cast<int32>(temp);
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
template <>
|
64
|
+
inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_INT64>(
|
65
|
+
io::CodedInputStream* input,
|
66
|
+
int64* value) {
|
67
|
+
uint64 temp;
|
68
|
+
if (!input->ReadVarint64(&temp)) return false;
|
69
|
+
*value = static_cast<int64>(temp);
|
70
|
+
return true;
|
71
|
+
}
|
72
|
+
template <>
|
73
|
+
inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>(
|
74
|
+
io::CodedInputStream* input,
|
75
|
+
uint32* value) {
|
76
|
+
return input->ReadVarint32(value);
|
77
|
+
}
|
78
|
+
template <>
|
79
|
+
inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_UINT64>(
|
80
|
+
io::CodedInputStream* input,
|
81
|
+
uint64* value) {
|
82
|
+
return input->ReadVarint64(value);
|
83
|
+
}
|
84
|
+
template <>
|
85
|
+
inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SINT32>(
|
86
|
+
io::CodedInputStream* input,
|
87
|
+
int32* value) {
|
88
|
+
uint32 temp;
|
89
|
+
if (!input->ReadVarint32(&temp)) return false;
|
90
|
+
*value = ZigZagDecode32(temp);
|
91
|
+
return true;
|
92
|
+
}
|
93
|
+
template <>
|
94
|
+
inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SINT64>(
|
95
|
+
io::CodedInputStream* input,
|
96
|
+
int64* value) {
|
97
|
+
uint64 temp;
|
98
|
+
if (!input->ReadVarint64(&temp)) return false;
|
99
|
+
*value = ZigZagDecode64(temp);
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
template <>
|
103
|
+
inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_FIXED32>(
|
104
|
+
io::CodedInputStream* input,
|
105
|
+
uint32* value) {
|
106
|
+
return input->ReadLittleEndian32(value);
|
107
|
+
}
|
108
|
+
template <>
|
109
|
+
inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_FIXED64>(
|
110
|
+
io::CodedInputStream* input,
|
111
|
+
uint64* value) {
|
112
|
+
return input->ReadLittleEndian64(value);
|
113
|
+
}
|
114
|
+
template <>
|
115
|
+
inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SFIXED32>(
|
116
|
+
io::CodedInputStream* input,
|
117
|
+
int32* value) {
|
118
|
+
uint32 temp;
|
119
|
+
if (!input->ReadLittleEndian32(&temp)) return false;
|
120
|
+
*value = static_cast<int32>(temp);
|
121
|
+
return true;
|
122
|
+
}
|
123
|
+
template <>
|
124
|
+
inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SFIXED64>(
|
125
|
+
io::CodedInputStream* input,
|
126
|
+
int64* value) {
|
127
|
+
uint64 temp;
|
128
|
+
if (!input->ReadLittleEndian64(&temp)) return false;
|
129
|
+
*value = static_cast<int64>(temp);
|
130
|
+
return true;
|
131
|
+
}
|
132
|
+
template <>
|
133
|
+
inline bool WireFormatLite::ReadPrimitive<float, WireFormatLite::TYPE_FLOAT>(
|
134
|
+
io::CodedInputStream* input,
|
135
|
+
float* value) {
|
136
|
+
uint32 temp;
|
137
|
+
if (!input->ReadLittleEndian32(&temp)) return false;
|
138
|
+
*value = DecodeFloat(temp);
|
139
|
+
return true;
|
140
|
+
}
|
141
|
+
template <>
|
142
|
+
inline bool WireFormatLite::ReadPrimitive<double, WireFormatLite::TYPE_DOUBLE>(
|
143
|
+
io::CodedInputStream* input,
|
144
|
+
double* value) {
|
145
|
+
uint64 temp;
|
146
|
+
if (!input->ReadLittleEndian64(&temp)) return false;
|
147
|
+
*value = DecodeDouble(temp);
|
148
|
+
return true;
|
149
|
+
}
|
150
|
+
template <>
|
151
|
+
inline bool WireFormatLite::ReadPrimitive<bool, WireFormatLite::TYPE_BOOL>(
|
152
|
+
io::CodedInputStream* input,
|
153
|
+
bool* value) {
|
154
|
+
uint32 temp;
|
155
|
+
if (!input->ReadVarint32(&temp)) return false;
|
156
|
+
*value = temp != 0;
|
157
|
+
return true;
|
158
|
+
}
|
159
|
+
template <>
|
160
|
+
inline bool WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
|
161
|
+
io::CodedInputStream* input,
|
162
|
+
int* value) {
|
163
|
+
uint32 temp;
|
164
|
+
if (!input->ReadVarint32(&temp)) return false;
|
165
|
+
*value = static_cast<int>(temp);
|
166
|
+
return true;
|
167
|
+
}
|
168
|
+
|
169
|
+
template <>
|
170
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
171
|
+
uint32, WireFormatLite::TYPE_FIXED32>(
|
172
|
+
const uint8* buffer,
|
173
|
+
uint32* value) {
|
174
|
+
return io::CodedInputStream::ReadLittleEndian32FromArray(buffer, value);
|
175
|
+
}
|
176
|
+
template <>
|
177
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
178
|
+
uint64, WireFormatLite::TYPE_FIXED64>(
|
179
|
+
const uint8* buffer,
|
180
|
+
uint64* value) {
|
181
|
+
return io::CodedInputStream::ReadLittleEndian64FromArray(buffer, value);
|
182
|
+
}
|
183
|
+
template <>
|
184
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
185
|
+
int32, WireFormatLite::TYPE_SFIXED32>(
|
186
|
+
const uint8* buffer,
|
187
|
+
int32* value) {
|
188
|
+
uint32 temp;
|
189
|
+
buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp);
|
190
|
+
*value = static_cast<int32>(temp);
|
191
|
+
return buffer;
|
192
|
+
}
|
193
|
+
template <>
|
194
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
195
|
+
int64, WireFormatLite::TYPE_SFIXED64>(
|
196
|
+
const uint8* buffer,
|
197
|
+
int64* value) {
|
198
|
+
uint64 temp;
|
199
|
+
buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp);
|
200
|
+
*value = static_cast<int64>(temp);
|
201
|
+
return buffer;
|
202
|
+
}
|
203
|
+
template <>
|
204
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
205
|
+
float, WireFormatLite::TYPE_FLOAT>(
|
206
|
+
const uint8* buffer,
|
207
|
+
float* value) {
|
208
|
+
uint32 temp;
|
209
|
+
buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp);
|
210
|
+
*value = DecodeFloat(temp);
|
211
|
+
return buffer;
|
212
|
+
}
|
213
|
+
template <>
|
214
|
+
inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
|
215
|
+
double, WireFormatLite::TYPE_DOUBLE>(
|
216
|
+
const uint8* buffer,
|
217
|
+
double* value) {
|
218
|
+
uint64 temp;
|
219
|
+
buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp);
|
220
|
+
*value = DecodeDouble(temp);
|
221
|
+
return buffer;
|
222
|
+
}
|
223
|
+
|
224
|
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
|
225
|
+
inline bool WireFormatLite::ReadRepeatedPrimitive(int, // tag_size, unused.
|
226
|
+
uint32 tag,
|
227
|
+
io::CodedInputStream* input,
|
228
|
+
RepeatedField<CType>* values) {
|
229
|
+
CType value;
|
230
|
+
if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
|
231
|
+
values->Add(value);
|
232
|
+
int elements_already_reserved = values->Capacity() - values->size();
|
233
|
+
while (elements_already_reserved > 0 && input->ExpectTag(tag)) {
|
234
|
+
if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
|
235
|
+
values->AddAlreadyReserved(value);
|
236
|
+
elements_already_reserved--;
|
237
|
+
}
|
238
|
+
return true;
|
239
|
+
}
|
240
|
+
|
241
|
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
|
242
|
+
inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
|
243
|
+
int tag_size,
|
244
|
+
uint32 tag,
|
245
|
+
io::CodedInputStream* input,
|
246
|
+
RepeatedField<CType>* values) {
|
247
|
+
GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size);
|
248
|
+
CType value;
|
249
|
+
if (!ReadPrimitive<CType, DeclaredType>(input, &value))
|
250
|
+
return false;
|
251
|
+
values->Add(value);
|
252
|
+
|
253
|
+
// For fixed size values, repeated values can be read more quickly by
|
254
|
+
// reading directly from a raw array.
|
255
|
+
//
|
256
|
+
// We can get a tight loop by only reading as many elements as can be
|
257
|
+
// added to the RepeatedField without having to do any resizing. Additionally,
|
258
|
+
// we only try to read as many elements as are available from the current
|
259
|
+
// buffer space. Doing so avoids having to perform boundary checks when
|
260
|
+
// reading the value: the maximum number of elements that can be read is
|
261
|
+
// known outside of the loop.
|
262
|
+
const void* void_pointer;
|
263
|
+
int size;
|
264
|
+
input->GetDirectBufferPointerInline(&void_pointer, &size);
|
265
|
+
if (size > 0) {
|
266
|
+
const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer);
|
267
|
+
// The number of bytes each type occupies on the wire.
|
268
|
+
const int per_value_size = tag_size + sizeof(value);
|
269
|
+
|
270
|
+
int elements_available = min(values->Capacity() - values->size(),
|
271
|
+
size / per_value_size);
|
272
|
+
int num_read = 0;
|
273
|
+
while (num_read < elements_available &&
|
274
|
+
(buffer = io::CodedInputStream::ExpectTagFromArray(
|
275
|
+
buffer, tag)) != NULL) {
|
276
|
+
buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value);
|
277
|
+
values->AddAlreadyReserved(value);
|
278
|
+
++num_read;
|
279
|
+
}
|
280
|
+
const int read_bytes = num_read * per_value_size;
|
281
|
+
if (read_bytes > 0) {
|
282
|
+
input->Skip(read_bytes);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
return true;
|
286
|
+
}
|
287
|
+
|
288
|
+
// Specializations of ReadRepeatedPrimitive for the fixed size types, which use
|
289
|
+
// the optimized code path.
|
290
|
+
#define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
|
291
|
+
template <> \
|
292
|
+
inline bool WireFormatLite::ReadRepeatedPrimitive< \
|
293
|
+
CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
|
294
|
+
int tag_size, \
|
295
|
+
uint32 tag, \
|
296
|
+
io::CodedInputStream* input, \
|
297
|
+
RepeatedField<CPPTYPE>* values) { \
|
298
|
+
return ReadRepeatedFixedSizePrimitive< \
|
299
|
+
CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
|
300
|
+
tag_size, tag, input, values); \
|
301
|
+
}
|
302
|
+
|
303
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32);
|
304
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64);
|
305
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32);
|
306
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64);
|
307
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT);
|
308
|
+
READ_REPEATED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE);
|
309
|
+
|
310
|
+
#undef READ_REPEATED_FIXED_SIZE_PRIMITIVE
|
311
|
+
|
312
|
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
|
313
|
+
bool WireFormatLite::ReadRepeatedPrimitiveNoInline(
|
314
|
+
int tag_size,
|
315
|
+
uint32 tag,
|
316
|
+
io::CodedInputStream* input,
|
317
|
+
RepeatedField<CType>* value) {
|
318
|
+
return ReadRepeatedPrimitive<CType, DeclaredType>(
|
319
|
+
tag_size, tag, input, value);
|
320
|
+
}
|
321
|
+
|
322
|
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
|
323
|
+
inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input,
|
324
|
+
RepeatedField<CType>* values) {
|
325
|
+
uint32 length;
|
326
|
+
if (!input->ReadVarint32(&length)) return false;
|
327
|
+
io::CodedInputStream::Limit limit = input->PushLimit(length);
|
328
|
+
while (input->BytesUntilLimit() > 0) {
|
329
|
+
CType value;
|
330
|
+
if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
|
331
|
+
values->Add(value);
|
332
|
+
}
|
333
|
+
input->PopLimit(limit);
|
334
|
+
return true;
|
335
|
+
}
|
336
|
+
|
337
|
+
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
|
338
|
+
bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input,
|
339
|
+
RepeatedField<CType>* values) {
|
340
|
+
return ReadPackedPrimitive<CType, DeclaredType>(input, values);
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
inline bool WireFormatLite::ReadGroup(int field_number,
|
345
|
+
io::CodedInputStream* input,
|
346
|
+
MessageLite* value) {
|
347
|
+
if (!input->IncrementRecursionDepth()) return false;
|
348
|
+
if (!value->MergePartialFromCodedStream(input)) return false;
|
349
|
+
input->DecrementRecursionDepth();
|
350
|
+
// Make sure the last thing read was an end tag for this group.
|
351
|
+
if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
|
352
|
+
return false;
|
353
|
+
}
|
354
|
+
return true;
|
355
|
+
}
|
356
|
+
inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input,
|
357
|
+
MessageLite* value) {
|
358
|
+
uint32 length;
|
359
|
+
if (!input->ReadVarint32(&length)) return false;
|
360
|
+
if (!input->IncrementRecursionDepth()) return false;
|
361
|
+
io::CodedInputStream::Limit limit = input->PushLimit(length);
|
362
|
+
if (!value->MergePartialFromCodedStream(input)) return false;
|
363
|
+
// Make sure that parsing stopped when the limit was hit, not at an endgroup
|
364
|
+
// tag.
|
365
|
+
if (!input->ConsumedEntireMessage()) return false;
|
366
|
+
input->PopLimit(limit);
|
367
|
+
input->DecrementRecursionDepth();
|
368
|
+
return true;
|
369
|
+
}
|
370
|
+
|
371
|
+
// We name the template parameter something long and extremely unlikely to occur
|
372
|
+
// elsewhere because a *qualified* member access expression designed to avoid
|
373
|
+
// virtual dispatch, C++03 [basic.lookup.classref] 3.4.5/4 requires that the
|
374
|
+
// name of the qualifying class to be looked up both in the context of the full
|
375
|
+
// expression (finding the template parameter) and in the context of the object
|
376
|
+
// whose member we are accessing. This could potentially find a nested type
|
377
|
+
// within that object. The standard goes on to require these names to refer to
|
378
|
+
// the same entity, which this collision would violate. The lack of a safe way
|
379
|
+
// to avoid this collision appears to be a defect in the standard, but until it
|
380
|
+
// is corrected, we choose the name to avoid accidental collisions.
|
381
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
382
|
+
inline bool WireFormatLite::ReadGroupNoVirtual(
|
383
|
+
int field_number, io::CodedInputStream* input,
|
384
|
+
MessageType_WorkAroundCppLookupDefect* value) {
|
385
|
+
if (!input->IncrementRecursionDepth()) return false;
|
386
|
+
if (!value->
|
387
|
+
MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input))
|
388
|
+
return false;
|
389
|
+
input->DecrementRecursionDepth();
|
390
|
+
// Make sure the last thing read was an end tag for this group.
|
391
|
+
if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
|
392
|
+
return false;
|
393
|
+
}
|
394
|
+
return true;
|
395
|
+
}
|
396
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
397
|
+
inline bool WireFormatLite::ReadMessageNoVirtual(
|
398
|
+
io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) {
|
399
|
+
uint32 length;
|
400
|
+
if (!input->ReadVarint32(&length)) return false;
|
401
|
+
if (!input->IncrementRecursionDepth()) return false;
|
402
|
+
io::CodedInputStream::Limit limit = input->PushLimit(length);
|
403
|
+
if (!value->
|
404
|
+
MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input))
|
405
|
+
return false;
|
406
|
+
// Make sure that parsing stopped when the limit was hit, not at an endgroup
|
407
|
+
// tag.
|
408
|
+
if (!input->ConsumedEntireMessage()) return false;
|
409
|
+
input->PopLimit(limit);
|
410
|
+
input->DecrementRecursionDepth();
|
411
|
+
return true;
|
412
|
+
}
|
413
|
+
|
414
|
+
// ===================================================================
|
415
|
+
|
416
|
+
inline void WireFormatLite::WriteTag(int field_number, WireType type,
|
417
|
+
io::CodedOutputStream* output) {
|
418
|
+
output->WriteTag(MakeTag(field_number, type));
|
419
|
+
}
|
420
|
+
|
421
|
+
inline void WireFormatLite::WriteInt32NoTag(int32 value,
|
422
|
+
io::CodedOutputStream* output) {
|
423
|
+
output->WriteVarint32SignExtended(value);
|
424
|
+
}
|
425
|
+
inline void WireFormatLite::WriteInt64NoTag(int64 value,
|
426
|
+
io::CodedOutputStream* output) {
|
427
|
+
output->WriteVarint64(static_cast<uint64>(value));
|
428
|
+
}
|
429
|
+
inline void WireFormatLite::WriteUInt32NoTag(uint32 value,
|
430
|
+
io::CodedOutputStream* output) {
|
431
|
+
output->WriteVarint32(value);
|
432
|
+
}
|
433
|
+
inline void WireFormatLite::WriteUInt64NoTag(uint64 value,
|
434
|
+
io::CodedOutputStream* output) {
|
435
|
+
output->WriteVarint64(value);
|
436
|
+
}
|
437
|
+
inline void WireFormatLite::WriteSInt32NoTag(int32 value,
|
438
|
+
io::CodedOutputStream* output) {
|
439
|
+
output->WriteVarint32(ZigZagEncode32(value));
|
440
|
+
}
|
441
|
+
inline void WireFormatLite::WriteSInt64NoTag(int64 value,
|
442
|
+
io::CodedOutputStream* output) {
|
443
|
+
output->WriteVarint64(ZigZagEncode64(value));
|
444
|
+
}
|
445
|
+
inline void WireFormatLite::WriteFixed32NoTag(uint32 value,
|
446
|
+
io::CodedOutputStream* output) {
|
447
|
+
output->WriteLittleEndian32(value);
|
448
|
+
}
|
449
|
+
inline void WireFormatLite::WriteFixed64NoTag(uint64 value,
|
450
|
+
io::CodedOutputStream* output) {
|
451
|
+
output->WriteLittleEndian64(value);
|
452
|
+
}
|
453
|
+
inline void WireFormatLite::WriteSFixed32NoTag(int32 value,
|
454
|
+
io::CodedOutputStream* output) {
|
455
|
+
output->WriteLittleEndian32(static_cast<uint32>(value));
|
456
|
+
}
|
457
|
+
inline void WireFormatLite::WriteSFixed64NoTag(int64 value,
|
458
|
+
io::CodedOutputStream* output) {
|
459
|
+
output->WriteLittleEndian64(static_cast<uint64>(value));
|
460
|
+
}
|
461
|
+
inline void WireFormatLite::WriteFloatNoTag(float value,
|
462
|
+
io::CodedOutputStream* output) {
|
463
|
+
output->WriteLittleEndian32(EncodeFloat(value));
|
464
|
+
}
|
465
|
+
inline void WireFormatLite::WriteDoubleNoTag(double value,
|
466
|
+
io::CodedOutputStream* output) {
|
467
|
+
output->WriteLittleEndian64(EncodeDouble(value));
|
468
|
+
}
|
469
|
+
inline void WireFormatLite::WriteBoolNoTag(bool value,
|
470
|
+
io::CodedOutputStream* output) {
|
471
|
+
output->WriteVarint32(value ? 1 : 0);
|
472
|
+
}
|
473
|
+
inline void WireFormatLite::WriteEnumNoTag(int value,
|
474
|
+
io::CodedOutputStream* output) {
|
475
|
+
output->WriteVarint32SignExtended(value);
|
476
|
+
}
|
477
|
+
|
478
|
+
// See comment on ReadGroupNoVirtual to understand the need for this template
|
479
|
+
// parameter name.
|
480
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
481
|
+
inline void WireFormatLite::WriteGroupNoVirtual(
|
482
|
+
int field_number, const MessageType_WorkAroundCppLookupDefect& value,
|
483
|
+
io::CodedOutputStream* output) {
|
484
|
+
WriteTag(field_number, WIRETYPE_START_GROUP, output);
|
485
|
+
value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
|
486
|
+
WriteTag(field_number, WIRETYPE_END_GROUP, output);
|
487
|
+
}
|
488
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
489
|
+
inline void WireFormatLite::WriteMessageNoVirtual(
|
490
|
+
int field_number, const MessageType_WorkAroundCppLookupDefect& value,
|
491
|
+
io::CodedOutputStream* output) {
|
492
|
+
WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
|
493
|
+
output->WriteVarint32(
|
494
|
+
value.MessageType_WorkAroundCppLookupDefect::GetCachedSize());
|
495
|
+
value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
|
496
|
+
}
|
497
|
+
|
498
|
+
// ===================================================================
|
499
|
+
|
500
|
+
inline uint8* WireFormatLite::WriteTagToArray(int field_number,
|
501
|
+
WireType type,
|
502
|
+
uint8* target) {
|
503
|
+
return io::CodedOutputStream::WriteTagToArray(MakeTag(field_number, type),
|
504
|
+
target);
|
505
|
+
}
|
506
|
+
|
507
|
+
inline uint8* WireFormatLite::WriteInt32NoTagToArray(int32 value,
|
508
|
+
uint8* target) {
|
509
|
+
return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target);
|
510
|
+
}
|
511
|
+
inline uint8* WireFormatLite::WriteInt64NoTagToArray(int64 value,
|
512
|
+
uint8* target) {
|
513
|
+
return io::CodedOutputStream::WriteVarint64ToArray(
|
514
|
+
static_cast<uint64>(value), target);
|
515
|
+
}
|
516
|
+
inline uint8* WireFormatLite::WriteUInt32NoTagToArray(uint32 value,
|
517
|
+
uint8* target) {
|
518
|
+
return io::CodedOutputStream::WriteVarint32ToArray(value, target);
|
519
|
+
}
|
520
|
+
inline uint8* WireFormatLite::WriteUInt64NoTagToArray(uint64 value,
|
521
|
+
uint8* target) {
|
522
|
+
return io::CodedOutputStream::WriteVarint64ToArray(value, target);
|
523
|
+
}
|
524
|
+
inline uint8* WireFormatLite::WriteSInt32NoTagToArray(int32 value,
|
525
|
+
uint8* target) {
|
526
|
+
return io::CodedOutputStream::WriteVarint32ToArray(ZigZagEncode32(value),
|
527
|
+
target);
|
528
|
+
}
|
529
|
+
inline uint8* WireFormatLite::WriteSInt64NoTagToArray(int64 value,
|
530
|
+
uint8* target) {
|
531
|
+
return io::CodedOutputStream::WriteVarint64ToArray(ZigZagEncode64(value),
|
532
|
+
target);
|
533
|
+
}
|
534
|
+
inline uint8* WireFormatLite::WriteFixed32NoTagToArray(uint32 value,
|
535
|
+
uint8* target) {
|
536
|
+
return io::CodedOutputStream::WriteLittleEndian32ToArray(value, target);
|
537
|
+
}
|
538
|
+
inline uint8* WireFormatLite::WriteFixed64NoTagToArray(uint64 value,
|
539
|
+
uint8* target) {
|
540
|
+
return io::CodedOutputStream::WriteLittleEndian64ToArray(value, target);
|
541
|
+
}
|
542
|
+
inline uint8* WireFormatLite::WriteSFixed32NoTagToArray(int32 value,
|
543
|
+
uint8* target) {
|
544
|
+
return io::CodedOutputStream::WriteLittleEndian32ToArray(
|
545
|
+
static_cast<uint32>(value), target);
|
546
|
+
}
|
547
|
+
inline uint8* WireFormatLite::WriteSFixed64NoTagToArray(int64 value,
|
548
|
+
uint8* target) {
|
549
|
+
return io::CodedOutputStream::WriteLittleEndian64ToArray(
|
550
|
+
static_cast<uint64>(value), target);
|
551
|
+
}
|
552
|
+
inline uint8* WireFormatLite::WriteFloatNoTagToArray(float value,
|
553
|
+
uint8* target) {
|
554
|
+
return io::CodedOutputStream::WriteLittleEndian32ToArray(EncodeFloat(value),
|
555
|
+
target);
|
556
|
+
}
|
557
|
+
inline uint8* WireFormatLite::WriteDoubleNoTagToArray(double value,
|
558
|
+
uint8* target) {
|
559
|
+
return io::CodedOutputStream::WriteLittleEndian64ToArray(EncodeDouble(value),
|
560
|
+
target);
|
561
|
+
}
|
562
|
+
inline uint8* WireFormatLite::WriteBoolNoTagToArray(bool value,
|
563
|
+
uint8* target) {
|
564
|
+
return io::CodedOutputStream::WriteVarint32ToArray(value ? 1 : 0, target);
|
565
|
+
}
|
566
|
+
inline uint8* WireFormatLite::WriteEnumNoTagToArray(int value,
|
567
|
+
uint8* target) {
|
568
|
+
return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target);
|
569
|
+
}
|
570
|
+
|
571
|
+
inline uint8* WireFormatLite::WriteInt32ToArray(int field_number,
|
572
|
+
int32 value,
|
573
|
+
uint8* target) {
|
574
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
575
|
+
return WriteInt32NoTagToArray(value, target);
|
576
|
+
}
|
577
|
+
inline uint8* WireFormatLite::WriteInt64ToArray(int field_number,
|
578
|
+
int64 value,
|
579
|
+
uint8* target) {
|
580
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
581
|
+
return WriteInt64NoTagToArray(value, target);
|
582
|
+
}
|
583
|
+
inline uint8* WireFormatLite::WriteUInt32ToArray(int field_number,
|
584
|
+
uint32 value,
|
585
|
+
uint8* target) {
|
586
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
587
|
+
return WriteUInt32NoTagToArray(value, target);
|
588
|
+
}
|
589
|
+
inline uint8* WireFormatLite::WriteUInt64ToArray(int field_number,
|
590
|
+
uint64 value,
|
591
|
+
uint8* target) {
|
592
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
593
|
+
return WriteUInt64NoTagToArray(value, target);
|
594
|
+
}
|
595
|
+
inline uint8* WireFormatLite::WriteSInt32ToArray(int field_number,
|
596
|
+
int32 value,
|
597
|
+
uint8* target) {
|
598
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
599
|
+
return WriteSInt32NoTagToArray(value, target);
|
600
|
+
}
|
601
|
+
inline uint8* WireFormatLite::WriteSInt64ToArray(int field_number,
|
602
|
+
int64 value,
|
603
|
+
uint8* target) {
|
604
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
605
|
+
return WriteSInt64NoTagToArray(value, target);
|
606
|
+
}
|
607
|
+
inline uint8* WireFormatLite::WriteFixed32ToArray(int field_number,
|
608
|
+
uint32 value,
|
609
|
+
uint8* target) {
|
610
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
|
611
|
+
return WriteFixed32NoTagToArray(value, target);
|
612
|
+
}
|
613
|
+
inline uint8* WireFormatLite::WriteFixed64ToArray(int field_number,
|
614
|
+
uint64 value,
|
615
|
+
uint8* target) {
|
616
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
|
617
|
+
return WriteFixed64NoTagToArray(value, target);
|
618
|
+
}
|
619
|
+
inline uint8* WireFormatLite::WriteSFixed32ToArray(int field_number,
|
620
|
+
int32 value,
|
621
|
+
uint8* target) {
|
622
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
|
623
|
+
return WriteSFixed32NoTagToArray(value, target);
|
624
|
+
}
|
625
|
+
inline uint8* WireFormatLite::WriteSFixed64ToArray(int field_number,
|
626
|
+
int64 value,
|
627
|
+
uint8* target) {
|
628
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
|
629
|
+
return WriteSFixed64NoTagToArray(value, target);
|
630
|
+
}
|
631
|
+
inline uint8* WireFormatLite::WriteFloatToArray(int field_number,
|
632
|
+
float value,
|
633
|
+
uint8* target) {
|
634
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
|
635
|
+
return WriteFloatNoTagToArray(value, target);
|
636
|
+
}
|
637
|
+
inline uint8* WireFormatLite::WriteDoubleToArray(int field_number,
|
638
|
+
double value,
|
639
|
+
uint8* target) {
|
640
|
+
target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
|
641
|
+
return WriteDoubleNoTagToArray(value, target);
|
642
|
+
}
|
643
|
+
inline uint8* WireFormatLite::WriteBoolToArray(int field_number,
|
644
|
+
bool value,
|
645
|
+
uint8* target) {
|
646
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
647
|
+
return WriteBoolNoTagToArray(value, target);
|
648
|
+
}
|
649
|
+
inline uint8* WireFormatLite::WriteEnumToArray(int field_number,
|
650
|
+
int value,
|
651
|
+
uint8* target) {
|
652
|
+
target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
|
653
|
+
return WriteEnumNoTagToArray(value, target);
|
654
|
+
}
|
655
|
+
|
656
|
+
inline uint8* WireFormatLite::WriteStringToArray(int field_number,
|
657
|
+
const string& value,
|
658
|
+
uint8* target) {
|
659
|
+
// String is for UTF-8 text only
|
660
|
+
// WARNING: In wire_format.cc, both strings and bytes are handled by
|
661
|
+
// WriteString() to avoid code duplication. If the implementations become
|
662
|
+
// different, you will need to update that usage.
|
663
|
+
target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
|
664
|
+
target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target);
|
665
|
+
return io::CodedOutputStream::WriteStringToArray(value, target);
|
666
|
+
}
|
667
|
+
inline uint8* WireFormatLite::WriteBytesToArray(int field_number,
|
668
|
+
const string& value,
|
669
|
+
uint8* target) {
|
670
|
+
target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
|
671
|
+
target = io::CodedOutputStream::WriteVarint32ToArray(value.size(), target);
|
672
|
+
return io::CodedOutputStream::WriteStringToArray(value, target);
|
673
|
+
}
|
674
|
+
|
675
|
+
|
676
|
+
inline uint8* WireFormatLite::WriteGroupToArray(int field_number,
|
677
|
+
const MessageLite& value,
|
678
|
+
uint8* target) {
|
679
|
+
target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
|
680
|
+
target = value.SerializeWithCachedSizesToArray(target);
|
681
|
+
return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
|
682
|
+
}
|
683
|
+
inline uint8* WireFormatLite::WriteMessageToArray(int field_number,
|
684
|
+
const MessageLite& value,
|
685
|
+
uint8* target) {
|
686
|
+
target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
|
687
|
+
target = io::CodedOutputStream::WriteVarint32ToArray(
|
688
|
+
value.GetCachedSize(), target);
|
689
|
+
return value.SerializeWithCachedSizesToArray(target);
|
690
|
+
}
|
691
|
+
|
692
|
+
// See comment on ReadGroupNoVirtual to understand the need for this template
|
693
|
+
// parameter name.
|
694
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
695
|
+
inline uint8* WireFormatLite::WriteGroupNoVirtualToArray(
|
696
|
+
int field_number, const MessageType_WorkAroundCppLookupDefect& value,
|
697
|
+
uint8* target) {
|
698
|
+
target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
|
699
|
+
target = value.MessageType_WorkAroundCppLookupDefect
|
700
|
+
::SerializeWithCachedSizesToArray(target);
|
701
|
+
return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
|
702
|
+
}
|
703
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
704
|
+
inline uint8* WireFormatLite::WriteMessageNoVirtualToArray(
|
705
|
+
int field_number, const MessageType_WorkAroundCppLookupDefect& value,
|
706
|
+
uint8* target) {
|
707
|
+
target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
|
708
|
+
target = io::CodedOutputStream::WriteVarint32ToArray(
|
709
|
+
value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target);
|
710
|
+
return value.MessageType_WorkAroundCppLookupDefect
|
711
|
+
::SerializeWithCachedSizesToArray(target);
|
712
|
+
}
|
713
|
+
|
714
|
+
// ===================================================================
|
715
|
+
|
716
|
+
inline int WireFormatLite::Int32Size(int32 value) {
|
717
|
+
return io::CodedOutputStream::VarintSize32SignExtended(value);
|
718
|
+
}
|
719
|
+
inline int WireFormatLite::Int64Size(int64 value) {
|
720
|
+
return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value));
|
721
|
+
}
|
722
|
+
inline int WireFormatLite::UInt32Size(uint32 value) {
|
723
|
+
return io::CodedOutputStream::VarintSize32(value);
|
724
|
+
}
|
725
|
+
inline int WireFormatLite::UInt64Size(uint64 value) {
|
726
|
+
return io::CodedOutputStream::VarintSize64(value);
|
727
|
+
}
|
728
|
+
inline int WireFormatLite::SInt32Size(int32 value) {
|
729
|
+
return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value));
|
730
|
+
}
|
731
|
+
inline int WireFormatLite::SInt64Size(int64 value) {
|
732
|
+
return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value));
|
733
|
+
}
|
734
|
+
inline int WireFormatLite::EnumSize(int value) {
|
735
|
+
return io::CodedOutputStream::VarintSize32SignExtended(value);
|
736
|
+
}
|
737
|
+
|
738
|
+
inline int WireFormatLite::StringSize(const string& value) {
|
739
|
+
return io::CodedOutputStream::VarintSize32(value.size()) +
|
740
|
+
value.size();
|
741
|
+
}
|
742
|
+
inline int WireFormatLite::BytesSize(const string& value) {
|
743
|
+
return io::CodedOutputStream::VarintSize32(value.size()) +
|
744
|
+
value.size();
|
745
|
+
}
|
746
|
+
|
747
|
+
|
748
|
+
inline int WireFormatLite::GroupSize(const MessageLite& value) {
|
749
|
+
return value.ByteSize();
|
750
|
+
}
|
751
|
+
inline int WireFormatLite::MessageSize(const MessageLite& value) {
|
752
|
+
int size = value.ByteSize();
|
753
|
+
return io::CodedOutputStream::VarintSize32(size) + size;
|
754
|
+
}
|
755
|
+
|
756
|
+
// See comment on ReadGroupNoVirtual to understand the need for this template
|
757
|
+
// parameter name.
|
758
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
759
|
+
inline int WireFormatLite::GroupSizeNoVirtual(
|
760
|
+
const MessageType_WorkAroundCppLookupDefect& value) {
|
761
|
+
return value.MessageType_WorkAroundCppLookupDefect::ByteSize();
|
762
|
+
}
|
763
|
+
template<typename MessageType_WorkAroundCppLookupDefect>
|
764
|
+
inline int WireFormatLite::MessageSizeNoVirtual(
|
765
|
+
const MessageType_WorkAroundCppLookupDefect& value) {
|
766
|
+
int size = value.MessageType_WorkAroundCppLookupDefect::ByteSize();
|
767
|
+
return io::CodedOutputStream::VarintSize32(size) + size;
|
768
|
+
}
|
769
|
+
|
770
|
+
} // namespace internal
|
771
|
+
} // namespace protobuf
|
772
|
+
|
773
|
+
} // namespace google
|
774
|
+
#endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
|