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,10 @@
|
|
1
|
+
all: \
|
2
|
+
RubyGenerator.h \
|
3
|
+
RubyGenerator.cpp
|
4
|
+
g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp
|
5
|
+
|
6
|
+
test:
|
7
|
+
rm -rf test/out/*
|
8
|
+
./protoc-ruby --proto_path=../defs --ruby_out=../out ../defs/atlas/util.proto ../defs/atlas/newman/*.proto
|
9
|
+
|
10
|
+
.PHONY: all test
|
@@ -0,0 +1,450 @@
|
|
1
|
+
#include "RubyGenerator.h"
|
2
|
+
|
3
|
+
namespace google {
|
4
|
+
namespace protobuf {
|
5
|
+
namespace compiler {
|
6
|
+
namespace ruby {
|
7
|
+
|
8
|
+
RubyGenerator::RubyGenerator() {} // Constructor
|
9
|
+
RubyGenerator::~RubyGenerator() {} // Destructor
|
10
|
+
|
11
|
+
// Generate one or more ruby source files for the given proto file.
|
12
|
+
bool RubyGenerator::Generate(const FileDescriptor* file,
|
13
|
+
const string& parameter,
|
14
|
+
GeneratorContext* context,
|
15
|
+
string* error) const {
|
16
|
+
file_ = file;
|
17
|
+
context_ = context;
|
18
|
+
|
19
|
+
filename = CreateRubyFileName(file_->name());
|
20
|
+
ns_vector.clear();
|
21
|
+
SplitStringUsing(file_->package(), ".", &ns_vector);
|
22
|
+
|
23
|
+
// Get a ZeroCopyOutputStream object of the data.
|
24
|
+
scoped_ptr<io::ZeroCopyOutputStream> output(context_->Open(filename));
|
25
|
+
|
26
|
+
// Check the data against Google's proto checking algorithm.
|
27
|
+
GOOGLE_CHECK(output.get());
|
28
|
+
|
29
|
+
// Get a printer.
|
30
|
+
io::Printer printer(output.get(), '$');
|
31
|
+
printer_ = &printer;
|
32
|
+
|
33
|
+
PrintGeneratedFileComment();
|
34
|
+
PrintGenericRequires();
|
35
|
+
PrintImportRequires();
|
36
|
+
|
37
|
+
PrintEnclosingNamespaceModules();
|
38
|
+
|
39
|
+
PrintEnumsForFileDescriptor(file_, false);
|
40
|
+
PrintNewLine();
|
41
|
+
PrintMessagesForFileDescriptor(file_, false);
|
42
|
+
PrintNewLine();
|
43
|
+
|
44
|
+
PrintEnumsForFileDescriptor(file_, true);
|
45
|
+
PrintMessagesForFileDescriptor(file_, true);
|
46
|
+
|
47
|
+
PrintServices();
|
48
|
+
|
49
|
+
PrintEnclosingNamespaceModuleEnds();
|
50
|
+
|
51
|
+
if (printer.failed()) {
|
52
|
+
*error = "An unknown error occured writing file " + filename;
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
} // end Generate()
|
59
|
+
|
60
|
+
//
|
61
|
+
///////////////////////////////////////////////// [ namespaces ] //////////////
|
62
|
+
//
|
63
|
+
|
64
|
+
void RubyGenerator::PrintEnclosingNamespaceModules() const {
|
65
|
+
PrintNewLine();
|
66
|
+
vector<string>::iterator iter;
|
67
|
+
map<string,string> data;
|
68
|
+
for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) {
|
69
|
+
data["ns"] = Constantize(*iter, false);
|
70
|
+
|
71
|
+
printer_->Print(data, "module $ns$");
|
72
|
+
PrintNewLine();
|
73
|
+
printer_->Indent();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
void RubyGenerator::PrintEnclosingNamespaceModuleEnds() const {
|
78
|
+
vector<string>::iterator iter;
|
79
|
+
for (iter = ns_vector.begin(); iter < ns_vector.end(); iter++) {
|
80
|
+
printer_->Outdent();
|
81
|
+
printer_->Print("end");
|
82
|
+
PrintNewLine();
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
//
|
88
|
+
///////////////////////////////////////////////// [ messages ] ////////////////
|
89
|
+
//
|
90
|
+
|
91
|
+
void RubyGenerator::PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const {
|
92
|
+
if (descriptor->message_type_count() > 0) {
|
93
|
+
if (print_fields) {
|
94
|
+
PrintComment("Message Fields", true);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
PrintComment("Message Classes", true);
|
98
|
+
}
|
99
|
+
|
100
|
+
for (int i = 0; i < descriptor->message_type_count(); i++) {
|
101
|
+
PrintMessage(descriptor->message_type(i), print_fields);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
void RubyGenerator::PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const {
|
107
|
+
for (int i = 0; i < descriptor->nested_type_count(); i++) {
|
108
|
+
PrintMessage(descriptor->nested_type(i), print_fields);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
//
|
112
|
+
// Print out the given descriptor message as a Ruby class.
|
113
|
+
void RubyGenerator::PrintMessage(const Descriptor* descriptor, bool print_fields) const {
|
114
|
+
map<string,string> data;
|
115
|
+
data["class_name"] = descriptor->name();
|
116
|
+
|
117
|
+
if (print_fields) {
|
118
|
+
printer_->Print(data, "class $class_name$");
|
119
|
+
PrintNewLine();
|
120
|
+
printer_->Indent();
|
121
|
+
|
122
|
+
if (descriptor->enum_type_count() > 0) {
|
123
|
+
PrintEnumsForDescriptor(descriptor, true);
|
124
|
+
}
|
125
|
+
|
126
|
+
if (descriptor->nested_type_count() > 0) {
|
127
|
+
PrintMessagesForDescriptor(descriptor, true);
|
128
|
+
}
|
129
|
+
|
130
|
+
PrintExtensionRangesForDescriptor(descriptor);
|
131
|
+
|
132
|
+
// Print Fields
|
133
|
+
if (descriptor->field_count() > 0) {
|
134
|
+
for (int i = 0; i < descriptor->field_count(); i++) {
|
135
|
+
PrintMessageField(descriptor->field(i));
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
// Print Extension Fields
|
140
|
+
if (descriptor->extension_count() > 0) {
|
141
|
+
for (int i = 0; i < descriptor->extension_count(); i++) {
|
142
|
+
PrintMessageField(descriptor->extension(i));
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
printer_->Outdent();
|
147
|
+
printer_->Print(data, "end");
|
148
|
+
PrintNewLine();
|
149
|
+
}
|
150
|
+
else if (DescriptorHasNestedTypes(descriptor)) {
|
151
|
+
printer_->Print(data, "class $class_name$ < ::Protobuf::Message");
|
152
|
+
PrintNewLine();
|
153
|
+
printer_->Indent();
|
154
|
+
|
155
|
+
if (descriptor->enum_type_count() > 0) {
|
156
|
+
PrintEnumsForDescriptor(descriptor, false);
|
157
|
+
}
|
158
|
+
|
159
|
+
if (descriptor->nested_type_count() > 0) {
|
160
|
+
PrintMessagesForDescriptor(descriptor, false);
|
161
|
+
}
|
162
|
+
|
163
|
+
printer_->Outdent();
|
164
|
+
printer_->Print(data, "end");
|
165
|
+
PrintNewLine();
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
printer_->Print(data, "class $class_name$ < ::Protobuf::Message; end");
|
169
|
+
}
|
170
|
+
|
171
|
+
PrintNewLine();
|
172
|
+
}
|
173
|
+
|
174
|
+
void RubyGenerator::PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const {
|
175
|
+
if (descriptor->extension_range_count() > 0) {
|
176
|
+
for (int i = 0; i < descriptor->extension_range_count(); i++) {
|
177
|
+
const Descriptor::ExtensionRange* range = descriptor->extension_range(i);
|
178
|
+
map<string,string> data;
|
179
|
+
data["message_class"] = Constantize(descriptor->full_name());
|
180
|
+
data["start"] = SimpleItoa(range->start);
|
181
|
+
data["end"] = SimpleItoa(range->end);
|
182
|
+
printer_->Print(data, "extensions $start$...$end$");
|
183
|
+
PrintNewLine();
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
// Print the given FieldDescriptor to the Message DSL methods.
|
189
|
+
void RubyGenerator::PrintMessageField(const FieldDescriptor* descriptor) const {
|
190
|
+
map<string,string> data;
|
191
|
+
data["field_presence"] = "";
|
192
|
+
data["field_name"] = descriptor->lowercase_name();
|
193
|
+
data["tag_number"] = SimpleItoa(descriptor->number());
|
194
|
+
data["data_type"] = "";
|
195
|
+
data["default_opt"] = "";
|
196
|
+
data["packed_opt"] = "";
|
197
|
+
data["deprecated_opt"] = "";
|
198
|
+
data["extension_opt"] = "";
|
199
|
+
|
200
|
+
if (descriptor->is_required()) {
|
201
|
+
data["field_presence"] = "required";
|
202
|
+
}
|
203
|
+
else if (descriptor->is_optional()) {
|
204
|
+
data["field_presence"] = "optional";
|
205
|
+
}
|
206
|
+
else if (descriptor->is_repeated()) {
|
207
|
+
data["field_presence"] = "repeated";
|
208
|
+
}
|
209
|
+
|
210
|
+
switch (descriptor->type()) {
|
211
|
+
// Primitives
|
212
|
+
case FieldDescriptor::TYPE_DOUBLE: data["data_type"] = "::Protobuf::Field::DoubleField"; break;
|
213
|
+
case FieldDescriptor::TYPE_FLOAT: data["data_type"] = "::Protobuf::Field::FloatField"; break;
|
214
|
+
case FieldDescriptor::TYPE_INT64: data["data_type"] = "::Protobuf::Field::Int64Field"; break;
|
215
|
+
case FieldDescriptor::TYPE_UINT64: data["data_type"] = "::Protobuf::Field::Uint64Field"; break;
|
216
|
+
case FieldDescriptor::TYPE_INT32: data["data_type"] = "::Protobuf::Field::Int32Field"; break;
|
217
|
+
case FieldDescriptor::TYPE_FIXED64: data["data_type"] = "::Protobuf::Field::Fixed64Field"; break;
|
218
|
+
case FieldDescriptor::TYPE_FIXED32: data["data_type"] = "::Protobuf::Field::Fixed32Field"; break;
|
219
|
+
case FieldDescriptor::TYPE_BOOL: data["data_type"] = "::Protobuf::Field::BoolField"; break;
|
220
|
+
case FieldDescriptor::TYPE_STRING: data["data_type"] = "::Protobuf::Field::StringField"; break;
|
221
|
+
case FieldDescriptor::TYPE_BYTES: data["data_type"] = "::Protobuf::Field::BytesField"; break;
|
222
|
+
case FieldDescriptor::TYPE_UINT32: data["data_type"] = "::Protobuf::Field::Uint32Field"; break;
|
223
|
+
case FieldDescriptor::TYPE_SFIXED32: data["data_type"] = "::Protobuf::Field::Sfixed32Field"; break;
|
224
|
+
case FieldDescriptor::TYPE_SFIXED64: data["data_type"] = "::Protobuf::Field::Sfixed64Field"; break;
|
225
|
+
case FieldDescriptor::TYPE_SINT32: data["data_type"] = "::Protobuf::Field::Sint32Field"; break;
|
226
|
+
case FieldDescriptor::TYPE_SINT64: data["data_type"] = "::Protobuf::Field::Sint64Field"; break;
|
227
|
+
|
228
|
+
// Enums
|
229
|
+
case FieldDescriptor::TYPE_ENUM:
|
230
|
+
data["data_type"] = Constantize(descriptor->enum_type()->full_name());
|
231
|
+
break;
|
232
|
+
|
233
|
+
// Messages
|
234
|
+
case FieldDescriptor::TYPE_GROUP:
|
235
|
+
case FieldDescriptor::TYPE_MESSAGE:
|
236
|
+
default:
|
237
|
+
data["data_type"] = Constantize(descriptor->message_type()->full_name());
|
238
|
+
break;
|
239
|
+
}
|
240
|
+
|
241
|
+
if (descriptor->has_default_value()) {
|
242
|
+
string value;
|
243
|
+
switch(descriptor->cpp_type()) {
|
244
|
+
case FieldDescriptor::CPPTYPE_INT32: value = SimpleItoa(descriptor->default_value_int32()); break;
|
245
|
+
case FieldDescriptor::CPPTYPE_INT64: value = SimpleItoa(descriptor->default_value_int64()); break;
|
246
|
+
case FieldDescriptor::CPPTYPE_UINT32: value = SimpleItoa(descriptor->default_value_uint32()); break;
|
247
|
+
case FieldDescriptor::CPPTYPE_UINT64: value = SimpleItoa(descriptor->default_value_uint64()); break;
|
248
|
+
case FieldDescriptor::CPPTYPE_DOUBLE: value = SimpleDtoa(descriptor->default_value_double()); break;
|
249
|
+
case FieldDescriptor::CPPTYPE_FLOAT: value = SimpleFtoa(descriptor->default_value_float()); break;
|
250
|
+
case FieldDescriptor::CPPTYPE_BOOL: value = descriptor->default_value_bool() ? "true" : "false"; break;
|
251
|
+
case FieldDescriptor::CPPTYPE_ENUM: value = FullEnumNamespace(descriptor->default_value_enum()); break;
|
252
|
+
case FieldDescriptor::CPPTYPE_STRING: value = "\"" + descriptor->default_value_string() + "\""; break;
|
253
|
+
default: break;
|
254
|
+
}
|
255
|
+
data["default_opt"] = strings::Substitute(", :default => $0", value);
|
256
|
+
}
|
257
|
+
|
258
|
+
if (descriptor->is_packable() && descriptor->options().has_packed()) {
|
259
|
+
string packed_bool = descriptor->options().packed() ? "true" : "false";
|
260
|
+
data["packed_opt"] = strings::Substitute(", :packed => $0", packed_bool);
|
261
|
+
}
|
262
|
+
|
263
|
+
if (descriptor->options().has_deprecated()) {
|
264
|
+
string deprecated_bool = descriptor->options().deprecated() ? "true" : "false";
|
265
|
+
data["deprecated_opt"] = strings::Substitute(", :deprecated => $0", deprecated_bool);
|
266
|
+
}
|
267
|
+
|
268
|
+
if (descriptor->is_extension()) {
|
269
|
+
data["extension_opt"] = ", :extension => true";
|
270
|
+
}
|
271
|
+
|
272
|
+
printer_->Print(data,
|
273
|
+
"$field_presence$ "
|
274
|
+
"$data_type$, "
|
275
|
+
":$field_name$, "
|
276
|
+
"$tag_number$"
|
277
|
+
"$default_opt$"
|
278
|
+
"$packed_opt$"
|
279
|
+
"$deprecated_opt$"
|
280
|
+
"$extension_opt$");
|
281
|
+
PrintNewLine();
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
//
|
286
|
+
///////////////////////////////////////////////// [ enums ] ///////////////////
|
287
|
+
//
|
288
|
+
|
289
|
+
void RubyGenerator::PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const {
|
290
|
+
for (int i = 0; i < descriptor->enum_type_count(); i++) {
|
291
|
+
PrintEnum(descriptor->enum_type(i), print_values);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
void RubyGenerator::PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const {
|
296
|
+
if (descriptor->enum_type_count() > 0) {
|
297
|
+
if (print_values) {
|
298
|
+
PrintComment("Enum Values", true);
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
PrintComment("Enum Classes", true);
|
302
|
+
}
|
303
|
+
|
304
|
+
for (int i = 0; i < descriptor->enum_type_count(); i++) {
|
305
|
+
PrintEnum(descriptor->enum_type(i), print_values);
|
306
|
+
}
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
// Print the given enum descriptor as a Ruby class.
|
311
|
+
void RubyGenerator::PrintEnum(const EnumDescriptor* descriptor, bool print_values) const {
|
312
|
+
map<string,string> data;
|
313
|
+
data["class_name"] = descriptor->name();
|
314
|
+
|
315
|
+
if (print_values) {
|
316
|
+
printer_->Print(data, "class $class_name$");
|
317
|
+
printer_->Indent();
|
318
|
+
PrintNewLine();
|
319
|
+
|
320
|
+
for (int i = 0; i < descriptor->value_count(); i++) {
|
321
|
+
PrintEnumValue(descriptor->value(i));
|
322
|
+
}
|
323
|
+
|
324
|
+
printer_->Outdent();
|
325
|
+
printer_->Print(data, "end");
|
326
|
+
PrintNewLine();
|
327
|
+
}
|
328
|
+
else {
|
329
|
+
printer_->Print(data, "class $class_name$ < ::Protobuf::Enum; end");
|
330
|
+
}
|
331
|
+
|
332
|
+
PrintNewLine();
|
333
|
+
}
|
334
|
+
|
335
|
+
// Print the given enum value to the Enum class DSL methods.
|
336
|
+
void RubyGenerator::PrintEnumValue(const EnumValueDescriptor* descriptor) const {
|
337
|
+
map<string,string> data;
|
338
|
+
data["name"] = descriptor->name();
|
339
|
+
data["number"] = ConvertIntToString(descriptor->number());
|
340
|
+
printer_->Print(data, "define :$name$, $number$");
|
341
|
+
PrintNewLine();
|
342
|
+
}
|
343
|
+
|
344
|
+
//
|
345
|
+
///////////////////////////////////////////////// [ services ] ////////////////
|
346
|
+
//
|
347
|
+
|
348
|
+
void RubyGenerator::PrintServices() const {
|
349
|
+
if (file_->service_count() > 0) {
|
350
|
+
PrintComment("Services", true);
|
351
|
+
for (int i = 0; i < file_->service_count(); i++) {
|
352
|
+
PrintService(file_->service(i));
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
// Print the given service as a Ruby class.
|
358
|
+
void RubyGenerator::PrintService(const ServiceDescriptor* descriptor) const {
|
359
|
+
map<string,string> data;
|
360
|
+
data["class_name"] = descriptor->name();
|
361
|
+
|
362
|
+
printer_->Print(data, "class $class_name$ < ::Protobuf::Rpc::Service");
|
363
|
+
PrintNewLine();
|
364
|
+
printer_->Indent();
|
365
|
+
|
366
|
+
for (int i = 0; i < descriptor->method_count(); i++) {
|
367
|
+
PrintServiceMethod(descriptor->method(i));
|
368
|
+
}
|
369
|
+
|
370
|
+
printer_->Outdent();
|
371
|
+
printer_->Print("end");
|
372
|
+
PrintNewLine();
|
373
|
+
}
|
374
|
+
|
375
|
+
// Print the rpc DSL declaration to the Ruby service class.
|
376
|
+
void RubyGenerator::PrintServiceMethod(const MethodDescriptor* descriptor) const {
|
377
|
+
map<string,string> data;
|
378
|
+
data["name"] = Underscore(descriptor->name());
|
379
|
+
data["request_klass"] = Constantize(descriptor->input_type()->full_name());
|
380
|
+
data["response_klass"] = Constantize(descriptor->output_type()->full_name());
|
381
|
+
printer_->Print(data, "rpc :$name$, $request_klass$, $response_klass$");
|
382
|
+
PrintNewLine();
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
//
|
387
|
+
///////////////////////////////////////////////// [ general ] ////////////////
|
388
|
+
//
|
389
|
+
|
390
|
+
// Print a header or one-line comment (as indicated by the as_header bool).
|
391
|
+
void RubyGenerator::PrintComment(string comment, bool as_header) const {
|
392
|
+
char format[] = "# $comment$\n";
|
393
|
+
char format_multi[] = "##\n# $comment$\n#\n";
|
394
|
+
|
395
|
+
map<string,string> data;
|
396
|
+
data["comment"] = comment;
|
397
|
+
|
398
|
+
if (as_header) {
|
399
|
+
printer_->Print(data, format_multi);
|
400
|
+
}
|
401
|
+
else {
|
402
|
+
printer_->Print(data, format);
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|
406
|
+
// Prints a require with the given ruby library.
|
407
|
+
void RubyGenerator::PrintRequire(string lib_name) const {
|
408
|
+
map<string,string> data;
|
409
|
+
data["lib"] = lib_name;
|
410
|
+
printer_->Print(data, "require '$lib$'\n");
|
411
|
+
}
|
412
|
+
|
413
|
+
// Print a comment indicating that the file was generated.
|
414
|
+
void RubyGenerator::PrintGeneratedFileComment() const {
|
415
|
+
PrintComment("This file is auto-generated. DO NOT EDIT!", true);
|
416
|
+
}
|
417
|
+
|
418
|
+
// Print out message requires as they pertain to the ruby library.
|
419
|
+
void RubyGenerator::PrintGenericRequires() const {
|
420
|
+
if (file_->message_type_count() > 0) {
|
421
|
+
PrintRequire("protobuf/message");
|
422
|
+
}
|
423
|
+
if (file_->service_count() > 0) {
|
424
|
+
PrintRequire("protobuf/rpc/service");
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
void RubyGenerator::PrintImportRequires() const {
|
429
|
+
if (file_->dependency_count() > 0) {
|
430
|
+
PrintNewLine();
|
431
|
+
PrintComment("Imports", true);
|
432
|
+
for (int i = 0; i < file_->dependency_count(); i++) {
|
433
|
+
PrintRequire(CreateRubyFileName(file_->dependency(i)->name(), true));
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
|
438
|
+
// Print a one-line comment.
|
439
|
+
void RubyGenerator::PrintComment(string comment) const {
|
440
|
+
PrintComment(comment, false);
|
441
|
+
}
|
442
|
+
|
443
|
+
void RubyGenerator::PrintNewLine() const {
|
444
|
+
printer_->Print("\n");
|
445
|
+
}
|
446
|
+
|
447
|
+
} // namespace ruby
|
448
|
+
} // namespace compiler
|
449
|
+
} // namespace protobuf
|
450
|
+
} // namespace google
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#ifndef GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H
|
2
|
+
#define GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H
|
3
|
+
|
4
|
+
#include <string>
|
5
|
+
#include <iostream>
|
6
|
+
#include <sstream>
|
7
|
+
#include <vector>
|
8
|
+
|
9
|
+
#include <google/protobuf/compiler/command_line_interface.h>
|
10
|
+
#include <google/protobuf/compiler/code_generator.h>
|
11
|
+
#include <google/protobuf/descriptor.h>
|
12
|
+
#include <google/protobuf/descriptor.pb.h>
|
13
|
+
#include <google/protobuf/io/zero_copy_stream.h>
|
14
|
+
#include <google/protobuf/io/printer.h>
|
15
|
+
#include <google/protobuf/stubs/substitute.h>
|
16
|
+
#include <google/protobuf/stubs/strutil.h>
|
17
|
+
|
18
|
+
namespace google {
|
19
|
+
namespace protobuf {
|
20
|
+
namespace compiler {
|
21
|
+
namespace ruby {
|
22
|
+
|
23
|
+
class LIBPROTOC_EXPORT RubyGenerator : public CodeGenerator {
|
24
|
+
public:
|
25
|
+
RubyGenerator();
|
26
|
+
~RubyGenerator();
|
27
|
+
|
28
|
+
// implemented Generate method from parent
|
29
|
+
bool Generate(const FileDescriptor* file,
|
30
|
+
const string& parameter,
|
31
|
+
GeneratorContext* context,
|
32
|
+
string* error) const;
|
33
|
+
|
34
|
+
|
35
|
+
private:
|
36
|
+
mutable GeneratorContext* context_;
|
37
|
+
mutable io::Printer* printer_;
|
38
|
+
mutable const FileDescriptor* file_;
|
39
|
+
mutable string filename;
|
40
|
+
mutable vector<string> ns_vector;
|
41
|
+
|
42
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RubyGenerator);
|
43
|
+
|
44
|
+
void PrintEnclosingNamespaceModules() const;
|
45
|
+
void PrintEnclosingNamespaceModuleEnds() const;
|
46
|
+
|
47
|
+
void PrintMessagesForDescriptor(const Descriptor* descriptor, bool print_fields) const;
|
48
|
+
void PrintMessagesForFileDescriptor(const FileDescriptor* descriptor, bool print_fields) const;
|
49
|
+
void PrintMessage(const Descriptor* descriptor, bool print_fields) const;
|
50
|
+
void PrintExtensionRangesForDescriptor(const Descriptor* descriptor) const;
|
51
|
+
void PrintMessageField(const FieldDescriptor* descriptor) const;
|
52
|
+
|
53
|
+
void PrintEnumsForDescriptor(const Descriptor* descriptor, bool print_values) const;
|
54
|
+
void PrintEnumsForFileDescriptor(const FileDescriptor* descriptor, bool print_values) const;
|
55
|
+
void PrintEnum(const EnumDescriptor* descriptor, bool print_values) const;
|
56
|
+
void PrintEnumValue(const EnumValueDescriptor* descriptor) const;
|
57
|
+
|
58
|
+
void PrintServices() const;
|
59
|
+
void PrintService(const ServiceDescriptor* descriptor) const;
|
60
|
+
void PrintServiceMethod(const MethodDescriptor* descriptor) const;
|
61
|
+
|
62
|
+
void PrintGeneratedFileComment() const;
|
63
|
+
void PrintGenericRequires() const;
|
64
|
+
void PrintImportRequires() const;
|
65
|
+
void PrintComment(string comment) const;
|
66
|
+
void PrintComment(string comment, bool as_header) const;
|
67
|
+
void PrintRequire(string lib_name) const;
|
68
|
+
void PrintNewLine() const;
|
69
|
+
|
70
|
+
// Take the proto file name, strip ".proto"
|
71
|
+
// from the end and add ".pb.rb"
|
72
|
+
static string CreateRubyFileName(const string proto_filename) {
|
73
|
+
return CreateRubyFileName(proto_filename, false);
|
74
|
+
}
|
75
|
+
|
76
|
+
static string CreateRubyFileName(const string proto_filename, bool for_require) {
|
77
|
+
string replacement = for_require ? ".pb" : ".pb.rb";
|
78
|
+
return StringReplace(proto_filename, ".proto", replacement, false);
|
79
|
+
}
|
80
|
+
|
81
|
+
static string ConvertIntToString(int number) {
|
82
|
+
stringstream stream;
|
83
|
+
stream << number;
|
84
|
+
return stream.str();
|
85
|
+
}
|
86
|
+
|
87
|
+
static string ConvertDoubleToString(double number) {
|
88
|
+
stringstream stream;
|
89
|
+
stream << number;
|
90
|
+
return stream.str();
|
91
|
+
}
|
92
|
+
|
93
|
+
static string ConvertFloatToString(float number) {
|
94
|
+
stringstream stream;
|
95
|
+
stream << number;
|
96
|
+
return stream.str();
|
97
|
+
}
|
98
|
+
|
99
|
+
static string Constantize(string full_path) {
|
100
|
+
return Constantize(full_path, true);
|
101
|
+
}
|
102
|
+
|
103
|
+
static string Constantize(string full_path, bool is_top_level) {
|
104
|
+
stringstream constantized;
|
105
|
+
|
106
|
+
if (is_top_level) {
|
107
|
+
constantized << "::";
|
108
|
+
}
|
109
|
+
|
110
|
+
string::iterator i;
|
111
|
+
bool segment_end = true;
|
112
|
+
for (i = full_path.begin(); i < full_path.end(); i++) {
|
113
|
+
char c = *i;
|
114
|
+
if (c == 46) { // period char
|
115
|
+
constantized << ':' << ':';
|
116
|
+
segment_end = true;
|
117
|
+
continue;
|
118
|
+
}
|
119
|
+
else if (c == 95) { // underscore char
|
120
|
+
segment_end = true;
|
121
|
+
continue;
|
122
|
+
}
|
123
|
+
else if (segment_end) {
|
124
|
+
if (c >= 97 && c <= 122) { // a-z chars
|
125
|
+
c -= 32;
|
126
|
+
}
|
127
|
+
segment_end = false;
|
128
|
+
}
|
129
|
+
constantized << c;
|
130
|
+
}
|
131
|
+
|
132
|
+
return constantized.str();
|
133
|
+
}
|
134
|
+
|
135
|
+
static string Underscore(string name) {
|
136
|
+
stringstream underscored;
|
137
|
+
|
138
|
+
string::iterator i;
|
139
|
+
for (i = name.begin(); i < name.end(); i++) {
|
140
|
+
char c = *i;
|
141
|
+
if (c >= 65 && c <= 90) { // a-z chars
|
142
|
+
if (i != name.begin()) {
|
143
|
+
underscored << '_';
|
144
|
+
}
|
145
|
+
c += 32;
|
146
|
+
}
|
147
|
+
underscored << c;
|
148
|
+
}
|
149
|
+
|
150
|
+
return underscored.str();
|
151
|
+
}
|
152
|
+
|
153
|
+
static string FullEnumNamespace(const EnumValueDescriptor* descriptor) {
|
154
|
+
string parent_enum_type = Constantize(descriptor->type()->full_name());
|
155
|
+
string enum_name = descriptor->name();
|
156
|
+
|
157
|
+
return strings::Substitute("$0::$1", parent_enum_type, enum_name);
|
158
|
+
}
|
159
|
+
|
160
|
+
static bool DescriptorHasNestedTypes(const Descriptor* descriptor) {
|
161
|
+
return (descriptor->enum_type_count() > 0 || descriptor->nested_type_count() > 0);
|
162
|
+
}
|
163
|
+
|
164
|
+
}; // class RubyGenerator
|
165
|
+
|
166
|
+
} // namespace ruby
|
167
|
+
} // namespace compiler
|
168
|
+
} // namespace protobuf
|
169
|
+
} // namespace google
|
170
|
+
|
171
|
+
#ifdef __cplusplus
|
172
|
+
extern "C" {
|
173
|
+
#endif
|
174
|
+
|
175
|
+
int _rprotoc_extern(int argc, char* argv[]) {
|
176
|
+
google::protobuf::compiler::CommandLineInterface cli;
|
177
|
+
|
178
|
+
google::protobuf::compiler::ruby::RubyGenerator ruby_generator;
|
179
|
+
cli.RegisterGenerator("--ruby_out", &ruby_generator,
|
180
|
+
"Generate Ruby-compatible protobuf message and service classes.");
|
181
|
+
|
182
|
+
return cli.Run(argc, argv);
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
|
187
|
+
Use for testing:
|
188
|
+
|
189
|
+
int main(int argc, char* argv[]) {
|
190
|
+
return _rprotoc_extern(argc, argv);
|
191
|
+
}
|
192
|
+
|
193
|
+
*/
|
194
|
+
|
195
|
+
#ifdef __cplusplus
|
196
|
+
}
|
197
|
+
#endif
|
198
|
+
|
199
|
+
#endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H
|
@@ -0,0 +1,36 @@
|
|
1
|
+
unless defined?(JRUBY_VERSION)
|
2
|
+
begin
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
include_directory = File.expand_path(File.join(File.dirname(__FILE__), "..", "protobuf-2.4.1", "src"))
|
6
|
+
|
7
|
+
$CPPFLAGS << " -I#{include_directory}"
|
8
|
+
$CPPFLAGS << " -Wall "
|
9
|
+
|
10
|
+
have_library("pthread")
|
11
|
+
have_library("protoc")
|
12
|
+
have_library("protobuf")
|
13
|
+
|
14
|
+
create_makefile('ruby_generator')
|
15
|
+
rescue ::Gem::Installer::ExtensionBuildError => ex
|
16
|
+
$stdout << <<-WARNING
|
17
|
+
Cannot compile native extension.
|
18
|
+
|
19
|
+
If you are running on Jruby or Windows you should compile protocol buffer
|
20
|
+
definitions on another computer and then use those definitions locally.
|
21
|
+
|
22
|
+
Only the compiler is restricted by this. The definitions should work without issue.
|
23
|
+
WARNING
|
24
|
+
$stdout << $/
|
25
|
+
end
|
26
|
+
else
|
27
|
+
$stdout << <<-WARNING
|
28
|
+
Cannot compile native extension.
|
29
|
+
|
30
|
+
If you are running on Jruby or Windows you should compile protocol buffer
|
31
|
+
definitions on another computer and then use those definitions locally.
|
32
|
+
|
33
|
+
Only the compiler is restricted by this. The definitions should work without issue.
|
34
|
+
WARNING
|
35
|
+
$stdout << $/
|
36
|
+
end
|
Binary file
|