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,424 @@
|
|
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
|
+
// Based on original Protocol Buffers design by
|
33
|
+
// Sanjay Ghemawat, Jeff Dean, and others.
|
34
|
+
//
|
35
|
+
// This header is logically internal, but is made public because it is used
|
36
|
+
// from protocol-compiler-generated code, which may reside in other components.
|
37
|
+
|
38
|
+
#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
39
|
+
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
40
|
+
|
41
|
+
#include <string>
|
42
|
+
#include <vector>
|
43
|
+
#include <google/protobuf/message.h>
|
44
|
+
#include <google/protobuf/unknown_field_set.h>
|
45
|
+
|
46
|
+
|
47
|
+
namespace google {
|
48
|
+
namespace protobuf {
|
49
|
+
class DescriptorPool;
|
50
|
+
// Generated code needs these to have been forward-declared. Easier to do it
|
51
|
+
// here than to print them inside every .pb.h file.
|
52
|
+
class FileDescriptor;
|
53
|
+
class EnumDescriptor;
|
54
|
+
}
|
55
|
+
|
56
|
+
namespace protobuf {
|
57
|
+
namespace internal {
|
58
|
+
|
59
|
+
// Defined in this file.
|
60
|
+
class GeneratedMessageReflection;
|
61
|
+
|
62
|
+
// Defined in other files.
|
63
|
+
class ExtensionSet; // extension_set.h
|
64
|
+
|
65
|
+
// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use
|
66
|
+
// by generated code. This class is just a big hack that reduces code
|
67
|
+
// size.
|
68
|
+
//
|
69
|
+
// A GeneratedMessageReflection is an implementation of Reflection
|
70
|
+
// which expects all fields to be backed by simple variables located in
|
71
|
+
// memory. The locations are given using a base pointer and a set of
|
72
|
+
// offsets.
|
73
|
+
//
|
74
|
+
// It is required that the user represents fields of each type in a standard
|
75
|
+
// way, so that GeneratedMessageReflection can cast the void* pointer to
|
76
|
+
// the appropriate type. For primitive fields and string fields, each field
|
77
|
+
// should be represented using the obvious C++ primitive type. Enums and
|
78
|
+
// Messages are different:
|
79
|
+
// - Singular Message fields are stored as a pointer to a Message. These
|
80
|
+
// should start out NULL, except for in the default instance where they
|
81
|
+
// should start out pointing to other default instances.
|
82
|
+
// - Enum fields are stored as an int. This int must always contain
|
83
|
+
// a valid value, such that EnumDescriptor::FindValueByNumber() would
|
84
|
+
// not return NULL.
|
85
|
+
// - Repeated fields are stored as RepeatedFields or RepeatedPtrFields
|
86
|
+
// of whatever type the individual field would be. Strings and
|
87
|
+
// Messages use RepeatedPtrFields while everything else uses
|
88
|
+
// RepeatedFields.
|
89
|
+
class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
|
90
|
+
public:
|
91
|
+
// Constructs a GeneratedMessageReflection.
|
92
|
+
// Parameters:
|
93
|
+
// descriptor: The descriptor for the message type being implemented.
|
94
|
+
// default_instance: The default instance of the message. This is only
|
95
|
+
// used to obtain pointers to default instances of embedded
|
96
|
+
// messages, which GetMessage() will return if the particular
|
97
|
+
// sub-message has not been initialized yet. (Thus, all
|
98
|
+
// embedded message fields *must* have non-NULL pointers
|
99
|
+
// in the default instance.)
|
100
|
+
// offsets: An array of ints giving the byte offsets, relative to
|
101
|
+
// the start of the message object, of each field. These can
|
102
|
+
// be computed at compile time using the
|
103
|
+
// GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined
|
104
|
+
// below.
|
105
|
+
// has_bits_offset: Offset in the message of an array of uint32s of size
|
106
|
+
// descriptor->field_count()/32, rounded up. This is a
|
107
|
+
// bitfield where each bit indicates whether or not the
|
108
|
+
// corresponding field of the message has been initialized.
|
109
|
+
// The bit for field index i is obtained by the expression:
|
110
|
+
// has_bits[i / 32] & (1 << (i % 32))
|
111
|
+
// unknown_fields_offset: Offset in the message of the UnknownFieldSet for
|
112
|
+
// the message.
|
113
|
+
// extensions_offset: Offset in the message of the ExtensionSet for the
|
114
|
+
// message, or -1 if the message type has no extension
|
115
|
+
// ranges.
|
116
|
+
// pool: DescriptorPool to search for extension definitions. Only
|
117
|
+
// used by FindKnownExtensionByName() and
|
118
|
+
// FindKnownExtensionByNumber().
|
119
|
+
// factory: MessageFactory to use to construct extension messages.
|
120
|
+
// object_size: The size of a message object of this type, as measured
|
121
|
+
// by sizeof().
|
122
|
+
GeneratedMessageReflection(const Descriptor* descriptor,
|
123
|
+
const Message* default_instance,
|
124
|
+
const int offsets[],
|
125
|
+
int has_bits_offset,
|
126
|
+
int unknown_fields_offset,
|
127
|
+
int extensions_offset,
|
128
|
+
const DescriptorPool* pool,
|
129
|
+
MessageFactory* factory,
|
130
|
+
int object_size);
|
131
|
+
~GeneratedMessageReflection();
|
132
|
+
|
133
|
+
// implements Reflection -------------------------------------------
|
134
|
+
|
135
|
+
const UnknownFieldSet& GetUnknownFields(const Message& message) const;
|
136
|
+
UnknownFieldSet* MutableUnknownFields(Message* message) const;
|
137
|
+
|
138
|
+
int SpaceUsed(const Message& message) const;
|
139
|
+
|
140
|
+
bool HasField(const Message& message, const FieldDescriptor* field) const;
|
141
|
+
int FieldSize(const Message& message, const FieldDescriptor* field) const;
|
142
|
+
void ClearField(Message* message, const FieldDescriptor* field) const;
|
143
|
+
void RemoveLast(Message* message, const FieldDescriptor* field) const;
|
144
|
+
void Swap(Message* message1, Message* message2) const;
|
145
|
+
void SwapElements(Message* message, const FieldDescriptor* field,
|
146
|
+
int index1, int index2) const;
|
147
|
+
void ListFields(const Message& message,
|
148
|
+
vector<const FieldDescriptor*>* output) const;
|
149
|
+
|
150
|
+
int32 GetInt32 (const Message& message,
|
151
|
+
const FieldDescriptor* field) const;
|
152
|
+
int64 GetInt64 (const Message& message,
|
153
|
+
const FieldDescriptor* field) const;
|
154
|
+
uint32 GetUInt32(const Message& message,
|
155
|
+
const FieldDescriptor* field) const;
|
156
|
+
uint64 GetUInt64(const Message& message,
|
157
|
+
const FieldDescriptor* field) const;
|
158
|
+
float GetFloat (const Message& message,
|
159
|
+
const FieldDescriptor* field) const;
|
160
|
+
double GetDouble(const Message& message,
|
161
|
+
const FieldDescriptor* field) const;
|
162
|
+
bool GetBool (const Message& message,
|
163
|
+
const FieldDescriptor* field) const;
|
164
|
+
string GetString(const Message& message,
|
165
|
+
const FieldDescriptor* field) const;
|
166
|
+
const string& GetStringReference(const Message& message,
|
167
|
+
const FieldDescriptor* field,
|
168
|
+
string* scratch) const;
|
169
|
+
const EnumValueDescriptor* GetEnum(const Message& message,
|
170
|
+
const FieldDescriptor* field) const;
|
171
|
+
const Message& GetMessage(const Message& message,
|
172
|
+
const FieldDescriptor* field,
|
173
|
+
MessageFactory* factory = NULL) const;
|
174
|
+
|
175
|
+
void SetInt32 (Message* message,
|
176
|
+
const FieldDescriptor* field, int32 value) const;
|
177
|
+
void SetInt64 (Message* message,
|
178
|
+
const FieldDescriptor* field, int64 value) const;
|
179
|
+
void SetUInt32(Message* message,
|
180
|
+
const FieldDescriptor* field, uint32 value) const;
|
181
|
+
void SetUInt64(Message* message,
|
182
|
+
const FieldDescriptor* field, uint64 value) const;
|
183
|
+
void SetFloat (Message* message,
|
184
|
+
const FieldDescriptor* field, float value) const;
|
185
|
+
void SetDouble(Message* message,
|
186
|
+
const FieldDescriptor* field, double value) const;
|
187
|
+
void SetBool (Message* message,
|
188
|
+
const FieldDescriptor* field, bool value) const;
|
189
|
+
void SetString(Message* message,
|
190
|
+
const FieldDescriptor* field,
|
191
|
+
const string& value) const;
|
192
|
+
void SetEnum (Message* message, const FieldDescriptor* field,
|
193
|
+
const EnumValueDescriptor* value) const;
|
194
|
+
Message* MutableMessage(Message* message, const FieldDescriptor* field,
|
195
|
+
MessageFactory* factory = NULL) const;
|
196
|
+
|
197
|
+
int32 GetRepeatedInt32 (const Message& message,
|
198
|
+
const FieldDescriptor* field, int index) const;
|
199
|
+
int64 GetRepeatedInt64 (const Message& message,
|
200
|
+
const FieldDescriptor* field, int index) const;
|
201
|
+
uint32 GetRepeatedUInt32(const Message& message,
|
202
|
+
const FieldDescriptor* field, int index) const;
|
203
|
+
uint64 GetRepeatedUInt64(const Message& message,
|
204
|
+
const FieldDescriptor* field, int index) const;
|
205
|
+
float GetRepeatedFloat (const Message& message,
|
206
|
+
const FieldDescriptor* field, int index) const;
|
207
|
+
double GetRepeatedDouble(const Message& message,
|
208
|
+
const FieldDescriptor* field, int index) const;
|
209
|
+
bool GetRepeatedBool (const Message& message,
|
210
|
+
const FieldDescriptor* field, int index) const;
|
211
|
+
string GetRepeatedString(const Message& message,
|
212
|
+
const FieldDescriptor* field, int index) const;
|
213
|
+
const string& GetRepeatedStringReference(const Message& message,
|
214
|
+
const FieldDescriptor* field,
|
215
|
+
int index, string* scratch) const;
|
216
|
+
const EnumValueDescriptor* GetRepeatedEnum(const Message& message,
|
217
|
+
const FieldDescriptor* field,
|
218
|
+
int index) const;
|
219
|
+
const Message& GetRepeatedMessage(const Message& message,
|
220
|
+
const FieldDescriptor* field,
|
221
|
+
int index) const;
|
222
|
+
|
223
|
+
// Set the value of a field.
|
224
|
+
void SetRepeatedInt32 (Message* message,
|
225
|
+
const FieldDescriptor* field, int index, int32 value) const;
|
226
|
+
void SetRepeatedInt64 (Message* message,
|
227
|
+
const FieldDescriptor* field, int index, int64 value) const;
|
228
|
+
void SetRepeatedUInt32(Message* message,
|
229
|
+
const FieldDescriptor* field, int index, uint32 value) const;
|
230
|
+
void SetRepeatedUInt64(Message* message,
|
231
|
+
const FieldDescriptor* field, int index, uint64 value) const;
|
232
|
+
void SetRepeatedFloat (Message* message,
|
233
|
+
const FieldDescriptor* field, int index, float value) const;
|
234
|
+
void SetRepeatedDouble(Message* message,
|
235
|
+
const FieldDescriptor* field, int index, double value) const;
|
236
|
+
void SetRepeatedBool (Message* message,
|
237
|
+
const FieldDescriptor* field, int index, bool value) const;
|
238
|
+
void SetRepeatedString(Message* message,
|
239
|
+
const FieldDescriptor* field, int index,
|
240
|
+
const string& value) const;
|
241
|
+
void SetRepeatedEnum(Message* message, const FieldDescriptor* field,
|
242
|
+
int index, const EnumValueDescriptor* value) const;
|
243
|
+
// Get a mutable pointer to a field with a message type.
|
244
|
+
Message* MutableRepeatedMessage(Message* message,
|
245
|
+
const FieldDescriptor* field,
|
246
|
+
int index) const;
|
247
|
+
|
248
|
+
void AddInt32 (Message* message,
|
249
|
+
const FieldDescriptor* field, int32 value) const;
|
250
|
+
void AddInt64 (Message* message,
|
251
|
+
const FieldDescriptor* field, int64 value) const;
|
252
|
+
void AddUInt32(Message* message,
|
253
|
+
const FieldDescriptor* field, uint32 value) const;
|
254
|
+
void AddUInt64(Message* message,
|
255
|
+
const FieldDescriptor* field, uint64 value) const;
|
256
|
+
void AddFloat (Message* message,
|
257
|
+
const FieldDescriptor* field, float value) const;
|
258
|
+
void AddDouble(Message* message,
|
259
|
+
const FieldDescriptor* field, double value) const;
|
260
|
+
void AddBool (Message* message,
|
261
|
+
const FieldDescriptor* field, bool value) const;
|
262
|
+
void AddString(Message* message,
|
263
|
+
const FieldDescriptor* field, const string& value) const;
|
264
|
+
void AddEnum(Message* message,
|
265
|
+
const FieldDescriptor* field,
|
266
|
+
const EnumValueDescriptor* value) const;
|
267
|
+
Message* AddMessage(Message* message, const FieldDescriptor* field,
|
268
|
+
MessageFactory* factory = NULL) const;
|
269
|
+
|
270
|
+
const FieldDescriptor* FindKnownExtensionByName(const string& name) const;
|
271
|
+
const FieldDescriptor* FindKnownExtensionByNumber(int number) const;
|
272
|
+
|
273
|
+
private:
|
274
|
+
friend class GeneratedMessage;
|
275
|
+
|
276
|
+
const Descriptor* descriptor_;
|
277
|
+
const Message* default_instance_;
|
278
|
+
const int* offsets_;
|
279
|
+
|
280
|
+
int has_bits_offset_;
|
281
|
+
int unknown_fields_offset_;
|
282
|
+
int extensions_offset_;
|
283
|
+
int object_size_;
|
284
|
+
|
285
|
+
const DescriptorPool* descriptor_pool_;
|
286
|
+
MessageFactory* message_factory_;
|
287
|
+
|
288
|
+
template <typename Type>
|
289
|
+
inline const Type& GetRaw(const Message& message,
|
290
|
+
const FieldDescriptor* field) const;
|
291
|
+
template <typename Type>
|
292
|
+
inline Type* MutableRaw(Message* message,
|
293
|
+
const FieldDescriptor* field) const;
|
294
|
+
template <typename Type>
|
295
|
+
inline const Type& DefaultRaw(const FieldDescriptor* field) const;
|
296
|
+
inline const Message* GetMessagePrototype(const FieldDescriptor* field) const;
|
297
|
+
|
298
|
+
inline const uint32* GetHasBits(const Message& message) const;
|
299
|
+
inline uint32* MutableHasBits(Message* message) const;
|
300
|
+
inline const ExtensionSet& GetExtensionSet(const Message& message) const;
|
301
|
+
inline ExtensionSet* MutableExtensionSet(Message* message) const;
|
302
|
+
|
303
|
+
inline bool HasBit(const Message& message,
|
304
|
+
const FieldDescriptor* field) const;
|
305
|
+
inline void SetBit(Message* message,
|
306
|
+
const FieldDescriptor* field) const;
|
307
|
+
inline void ClearBit(Message* message,
|
308
|
+
const FieldDescriptor* field) const;
|
309
|
+
|
310
|
+
template <typename Type>
|
311
|
+
inline const Type& GetField(const Message& message,
|
312
|
+
const FieldDescriptor* field) const;
|
313
|
+
template <typename Type>
|
314
|
+
inline void SetField(Message* message,
|
315
|
+
const FieldDescriptor* field, const Type& value) const;
|
316
|
+
template <typename Type>
|
317
|
+
inline Type* MutableField(Message* message,
|
318
|
+
const FieldDescriptor* field) const;
|
319
|
+
template <typename Type>
|
320
|
+
inline const Type& GetRepeatedField(const Message& message,
|
321
|
+
const FieldDescriptor* field,
|
322
|
+
int index) const;
|
323
|
+
template <typename Type>
|
324
|
+
inline const Type& GetRepeatedPtrField(const Message& message,
|
325
|
+
const FieldDescriptor* field,
|
326
|
+
int index) const;
|
327
|
+
template <typename Type>
|
328
|
+
inline void SetRepeatedField(Message* message,
|
329
|
+
const FieldDescriptor* field, int index,
|
330
|
+
Type value) const;
|
331
|
+
template <typename Type>
|
332
|
+
inline Type* MutableRepeatedField(Message* message,
|
333
|
+
const FieldDescriptor* field,
|
334
|
+
int index) const;
|
335
|
+
template <typename Type>
|
336
|
+
inline void AddField(Message* message,
|
337
|
+
const FieldDescriptor* field, const Type& value) const;
|
338
|
+
template <typename Type>
|
339
|
+
inline Type* AddField(Message* message,
|
340
|
+
const FieldDescriptor* field) const;
|
341
|
+
|
342
|
+
int GetExtensionNumberOrDie(const Descriptor* type) const;
|
343
|
+
|
344
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection);
|
345
|
+
};
|
346
|
+
|
347
|
+
// Returns the offset of the given field within the given aggregate type.
|
348
|
+
// This is equivalent to the ANSI C offsetof() macro. However, according
|
349
|
+
// to the C++ standard, offsetof() only works on POD types, and GCC
|
350
|
+
// enforces this requirement with a warning. In practice, this rule is
|
351
|
+
// unnecessarily strict; there is probably no compiler or platform on
|
352
|
+
// which the offsets of the direct fields of a class are non-constant.
|
353
|
+
// Fields inherited from superclasses *can* have non-constant offsets,
|
354
|
+
// but that's not what this macro will be used for.
|
355
|
+
//
|
356
|
+
// Note that we calculate relative to the pointer value 16 here since if we
|
357
|
+
// just use zero, GCC complains about dereferencing a NULL pointer. We
|
358
|
+
// choose 16 rather than some other number just in case the compiler would
|
359
|
+
// be confused by an unaligned pointer.
|
360
|
+
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \
|
361
|
+
static_cast<int>( \
|
362
|
+
reinterpret_cast<const char*>( \
|
363
|
+
&reinterpret_cast<const TYPE*>(16)->FIELD) - \
|
364
|
+
reinterpret_cast<const char*>(16))
|
365
|
+
|
366
|
+
// There are some places in proto2 where dynamic_cast would be useful as an
|
367
|
+
// optimization. For example, take Message::MergeFrom(const Message& other).
|
368
|
+
// For a given generated message FooMessage, we generate these two methods:
|
369
|
+
// void MergeFrom(const FooMessage& other);
|
370
|
+
// void MergeFrom(const Message& other);
|
371
|
+
// The former method can be implemented directly in terms of FooMessage's
|
372
|
+
// inline accessors, but the latter method must work with the reflection
|
373
|
+
// interface. However, if the parameter to the latter method is actually of
|
374
|
+
// type FooMessage, then we'd like to be able to just call the other method
|
375
|
+
// as an optimization. So, we use dynamic_cast to check this.
|
376
|
+
//
|
377
|
+
// That said, dynamic_cast requires RTTI, which many people like to disable
|
378
|
+
// for performance and code size reasons. When RTTI is not available, we
|
379
|
+
// still need to produce correct results. So, in this case we have to fall
|
380
|
+
// back to using reflection, which is what we would have done anyway if the
|
381
|
+
// objects were not of the exact same class.
|
382
|
+
//
|
383
|
+
// dynamic_cast_if_available() implements this logic. If RTTI is
|
384
|
+
// enabled, it does a dynamic_cast. If RTTI is disabled, it just returns
|
385
|
+
// NULL.
|
386
|
+
//
|
387
|
+
// If you need to compile without RTTI, simply #define GOOGLE_PROTOBUF_NO_RTTI.
|
388
|
+
// On MSVC, this should be detected automatically.
|
389
|
+
template<typename To, typename From>
|
390
|
+
inline To dynamic_cast_if_available(From from) {
|
391
|
+
#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI))
|
392
|
+
return NULL;
|
393
|
+
#else
|
394
|
+
return dynamic_cast<To>(from);
|
395
|
+
#endif
|
396
|
+
}
|
397
|
+
|
398
|
+
// Helper for EnumType_Parse functions: try to parse the string 'name' as an
|
399
|
+
// enum name of the given type, returning true and filling in value on success,
|
400
|
+
// or returning false and leaving value unchanged on failure.
|
401
|
+
LIBPROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor,
|
402
|
+
const string& name,
|
403
|
+
int* value);
|
404
|
+
|
405
|
+
template<typename EnumType>
|
406
|
+
bool ParseNamedEnum(const EnumDescriptor* descriptor,
|
407
|
+
const string& name,
|
408
|
+
EnumType* value) {
|
409
|
+
int tmp;
|
410
|
+
if (!ParseNamedEnum(descriptor, name, &tmp)) return false;
|
411
|
+
*value = static_cast<EnumType>(tmp);
|
412
|
+
return true;
|
413
|
+
}
|
414
|
+
|
415
|
+
// Just a wrapper around printing the name of a value. The main point of this
|
416
|
+
// function is not to be inlined, so that you can do this without including
|
417
|
+
// descriptor.h.
|
418
|
+
LIBPROTOBUF_EXPORT const string& NameOfEnum(const EnumDescriptor* descriptor, int value);
|
419
|
+
|
420
|
+
} // namespace internal
|
421
|
+
} // namespace protobuf
|
422
|
+
|
423
|
+
} // namespace google
|
424
|
+
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
@@ -0,0 +1,82 @@
|
|
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
|
+
// Based on original Protocol Buffers design by
|
33
|
+
// Sanjay Ghemawat, Jeff Dean, and others.
|
34
|
+
//
|
35
|
+
// This file contains miscellaneous helper code used by generated code --
|
36
|
+
// including lite types -- but which should not be used directly by users.
|
37
|
+
|
38
|
+
#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|
39
|
+
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|
40
|
+
|
41
|
+
#include <string>
|
42
|
+
|
43
|
+
#include <google/protobuf/stubs/common.h>
|
44
|
+
|
45
|
+
|
46
|
+
namespace google {
|
47
|
+
namespace protobuf {
|
48
|
+
namespace io {
|
49
|
+
class CodedInputStream; // coded_stream.h
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
namespace protobuf {
|
54
|
+
namespace internal {
|
55
|
+
|
56
|
+
// Annotation for the compiler to emit a deprecation message if a field marked
|
57
|
+
// with option 'deprecated=true' is used in the code, or for other things in
|
58
|
+
// generated code which are deprecated.
|
59
|
+
//
|
60
|
+
// For internal use in the pb.cc files, deprecation warnings are suppressed
|
61
|
+
// there.
|
62
|
+
#undef DEPRECATED_PROTOBUF_FIELD
|
63
|
+
#if !defined(INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION)
|
64
|
+
# define PROTOBUF_DEPRECATED GOOGLE_ATTRIBUTE_DEPRECATED
|
65
|
+
#else
|
66
|
+
# define PROTOBUF_DEPRECATED
|
67
|
+
#endif
|
68
|
+
|
69
|
+
|
70
|
+
// Constants for special floating point values.
|
71
|
+
double Infinity();
|
72
|
+
double NaN();
|
73
|
+
|
74
|
+
// Constant used for empty default strings.
|
75
|
+
extern const ::std::string kEmptyString;
|
76
|
+
|
77
|
+
|
78
|
+
} // namespace internal
|
79
|
+
} // namespace protobuf
|
80
|
+
|
81
|
+
} // namespace google
|
82
|
+
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|