protobuf 1.4.2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Rakefile +7 -7
- data/bin/rpc_server +2 -188
- data/bin/rprotoc +44 -38
- data/examples/addressbook.pb.rb +2 -2
- data/ext/Makefile +11 -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/RubyGenerator.cpp +435 -0
- data/ext/ruby_generator/RubyGenerator.h +180 -0
- data/ext/ruby_generator/extconf.rb +24 -0
- data/lib/protobuf.rb +55 -33
- data/lib/protobuf/cli.rb +176 -0
- data/lib/protobuf/common/logger.rb +11 -11
- data/lib/protobuf/{message/enum.rb → enum.rb} +0 -10
- data/lib/protobuf/evented.rb +22 -0
- data/lib/protobuf/field.rb +57 -0
- data/lib/protobuf/field/base_field.rb +210 -0
- data/lib/protobuf/field/bool_field.rb +24 -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 +58 -0
- data/lib/protobuf/field/extension_fields.rb +24 -0
- data/lib/protobuf/field/field_array.rb +55 -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 +29 -0
- data/lib/protobuf/field/int32_field.rb +10 -0
- data/lib/protobuf/field/int64_field.rb +10 -0
- data/lib/protobuf/field/integer_field.rb +19 -0
- data/lib/protobuf/field/message_field.rb +51 -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 +10 -0
- data/lib/protobuf/field/sint64_field.rb +10 -0
- data/lib/protobuf/field/string_field.rb +14 -0
- data/lib/protobuf/field/uint32_field.rb +10 -0
- data/lib/protobuf/field/uint64_field.rb +10 -0
- data/lib/protobuf/field/varint_field.rb +63 -0
- data/lib/protobuf/message.rb +376 -0
- data/lib/protobuf/message/message.rb +1 -475
- data/lib/protobuf/rpc/buffer.rb +1 -1
- data/lib/protobuf/rpc/client.rb +26 -26
- data/lib/protobuf/rpc/connector.rb +15 -14
- data/lib/protobuf/rpc/connectors/eventmachine.rb +13 -13
- data/lib/protobuf/rpc/rpc.pb.rb +39 -28
- data/lib/protobuf/rpc/server.rb +7 -28
- data/lib/protobuf/rpc/servers/evented_runner.rb +15 -15
- data/lib/protobuf/rpc/servers/socket/server.rb +2 -1
- data/lib/protobuf/rpc/servers/socket_runner.rb +5 -6
- data/lib/protobuf/rpc/servers/zmq_runner.rb +4 -5
- data/lib/protobuf/socket.rb +22 -0
- data/lib/protobuf/version.rb +2 -1
- data/lib/protobuf/zmq.rb +21 -0
- data/proto/rpc.pb.rb +48 -0
- data/protobuf.gemspec +14 -6
- data/spec/benchmark/tasks.rb +42 -23
- data/spec/functional/evented_server_spec.rb +2 -0
- data/spec/functional/socket_server_spec.rb +22 -26
- data/spec/functional/zmq_server_spec.rb +22 -26
- data/spec/lib/protobuf/cli_spec.rb +182 -0
- data/spec/{unit → lib/protobuf}/common/logger_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/enum_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/message_spec.rb +0 -0
- data/spec/{unit → lib/protobuf}/rpc/client_spec.rb +6 -4
- data/spec/lib/protobuf/rpc/connector_spec.rb +41 -0
- data/spec/{unit → lib/protobuf}/rpc/connectors/base_spec.rb +18 -18
- data/spec/{unit → lib/protobuf}/rpc/connectors/common_spec.rb +20 -20
- data/spec/{unit → lib/protobuf}/rpc/connectors/socket_spec.rb +9 -8
- data/spec/{unit → lib/protobuf}/rpc/connectors/zmq_spec.rb +1 -1
- data/spec/{unit → lib/protobuf}/rpc/servers/evented_server_spec.rb +4 -4
- data/spec/{unit → lib/protobuf}/rpc/servers/socket_server_spec.rb +11 -23
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/broker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/server_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/util_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/worker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/service_spec.rb +0 -0
- data/spec/proto/test.pb.rb +48 -25
- data/spec/spec_helper.rb +9 -15
- data/spec/support/all.rb +7 -0
- data/spec/{helper → support}/server.rb +5 -7
- data/spec/{helper → support}/silent_constants.rb +4 -0
- data/spec/support/test_app_file.rb +2 -0
- data/spec/{helper → support}/tolerance_matcher.rb +0 -0
- data/test/proto/types.pb.rb +1 -1
- data/test/test_addressbook.rb +1 -1
- data/test/test_enum_value.rb +1 -1
- data/test/test_standard_message.rb +1 -1
- metadata +243 -107
- data/lib/protobuf/common/util.rb +0 -59
- data/lib/protobuf/compiler/compiler.rb +0 -52
- data/lib/protobuf/compiler/nodes.rb +0 -323
- data/lib/protobuf/compiler/proto.y +0 -216
- data/lib/protobuf/compiler/proto2.ebnf +0 -79
- data/lib/protobuf/compiler/proto_parser.rb +0 -1425
- data/lib/protobuf/compiler/template/rpc_service_implementation.erb +0 -42
- data/lib/protobuf/compiler/visitors.rb +0 -282
- data/lib/protobuf/descriptor/descriptor.proto +0 -286
- data/lib/protobuf/descriptor/descriptor.rb +0 -55
- data/lib/protobuf/descriptor/descriptor_builder.rb +0 -143
- data/lib/protobuf/descriptor/descriptor_proto.rb +0 -138
- data/lib/protobuf/descriptor/enum_descriptor.rb +0 -33
- data/lib/protobuf/descriptor/field_descriptor.rb +0 -49
- data/lib/protobuf/descriptor/file_descriptor.rb +0 -37
- data/lib/protobuf/message/field.rb +0 -684
- data/lib/protobuf/message/protoable.rb +0 -38
- data/spec/helper/all.rb +0 -7
- data/spec/unit/common/util_spec.rb +0 -17
- data/spec/unit/rpc/connector_spec.rb +0 -31
- data/spec/unit/rpc/connectors/eventmachine_client_spec.rb +0 -32
- data/spec/unit/rpc/connectors/eventmachine_spec.rb +0 -0
- data/test/check_unbuild.rb +0 -30
- data/test/test_compiler.rb +0 -325
- data/test/test_descriptor.rb +0 -122
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -4,13 +4,6 @@ $:.push File.expand_path("./spec", File.dirname(__FILE__))
|
|
4
4
|
require "bundler/gem_tasks"
|
5
5
|
require "benchmark/tasks"
|
6
6
|
|
7
|
-
require 'rake/testtask'
|
8
|
-
Rake::TestTask.new(:test) do |test|
|
9
|
-
test.libs << 'test:.'
|
10
|
-
test.pattern = 'test/**/test_*.rb'
|
11
|
-
test.verbose = true
|
12
|
-
end
|
13
|
-
|
14
7
|
require 'rspec/core/rake_task'
|
15
8
|
|
16
9
|
desc 'Default: run specs.'
|
@@ -18,3 +11,10 @@ task :default => :spec
|
|
18
11
|
|
19
12
|
desc "Run specs"
|
20
13
|
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
##
|
16
|
+
# Rake-compiler
|
17
|
+
#
|
18
|
+
require 'rake/extensiontask'
|
19
|
+
|
20
|
+
Rake::ExtensionTask.new("ruby_generator")
|
data/bin/rpc_server
CHANGED
@@ -1,191 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
require 'logger'
|
6
|
-
require 'protobuf/version'
|
7
|
-
require 'protobuf/rpc/servers/evented_runner'
|
8
|
-
require 'protobuf/rpc/servers/socket_runner'
|
9
|
-
require 'protobuf/rpc/servers/zmq_runner'
|
3
|
+
require 'protobuf/cli'
|
4
|
+
::Protobuf::CLI.start(ARGV)
|
10
5
|
|
11
|
-
# Default options
|
12
|
-
server = OpenStruct.new({
|
13
|
-
:app => nil,
|
14
|
-
:env => ENV['RPC_SERVER_ENV'] || 'development',
|
15
|
-
:pre_cache_definitions => false,
|
16
|
-
:gc_pause_during_request => false,
|
17
|
-
:gc_pause_during_serialization => false,
|
18
|
-
:host => '127.0.0.1',
|
19
|
-
:port => 9595,
|
20
|
-
:backlog => 100,
|
21
|
-
:threshold => 100,
|
22
|
-
:log => File.expand_path('./protobuf.log'),
|
23
|
-
:level => ::Logger::INFO,
|
24
|
-
:runner => ::Protobuf::Rpc::EventedRunner,
|
25
|
-
:debug => false,
|
26
|
-
:stopped_during_startup => false
|
27
|
-
})
|
28
|
-
|
29
|
-
class ClientServerParse
|
30
|
-
def self.parse_client(value)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.parse_server(value)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
parser = OptionParser.new do |opts|
|
38
|
-
opts.banner = "Usage: rpc_server [options] app_file.rb"
|
39
|
-
|
40
|
-
opts.on("-e ENVIRONMENT", "--env=ENVIRONMENT", "Environment to run the server") do |v|
|
41
|
-
server.env = ENV['RACK_ENV'] = ENV['RAILS_ENV'] = ENV['APP_ENV'] = v
|
42
|
-
end
|
43
|
-
|
44
|
-
opts.on("-o HOST", "--host=HOST", "Server host") do |v|
|
45
|
-
server.host = v
|
46
|
-
end
|
47
|
-
|
48
|
-
opts.on("-p PORT", "--port=PORT", Integer, "Server port") do |v|
|
49
|
-
server.port = v
|
50
|
-
end
|
51
|
-
|
52
|
-
opts.on("-l LOG_FILE", "--log=LOG_FILE", "Log file or device") do |v|
|
53
|
-
server.log = v
|
54
|
-
end
|
55
|
-
|
56
|
-
opts.on("-v N", "--level=N", Integer, "Log level to use, 0-5 (see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/)") do |v|
|
57
|
-
server.level = v.to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
opts.on("-b N", "--backlog=N", Integer, "Backlog for listening socket when using Socket Server") do |v|
|
61
|
-
server.backlog = v.to_i
|
62
|
-
end
|
63
|
-
|
64
|
-
opts.on("-t N", "--threshold=N", Integer, "Multi-threaded Socket Server cleanup threshold") do |v|
|
65
|
-
server.threshold = v.to_i
|
66
|
-
end
|
67
|
-
|
68
|
-
opts.on("-c", "--client_socket", "Socket Mode for client connections (No EventMachine)") do |v|
|
69
|
-
ENV['PB_CLIENT_TYPE'] = "Socket"
|
70
|
-
end
|
71
|
-
|
72
|
-
opts.on("-s", "--socket", "Socket Server Mode (No EventMachine)") do |v|
|
73
|
-
ENV['PB_SERVER_TYPE'] = "Socket"
|
74
|
-
server.runner = ::Protobuf::Rpc::SocketRunner
|
75
|
-
end
|
76
|
-
|
77
|
-
opts.on("-z", "--zmq", "ZeroMQ Socket Mode for client and server connections (they must be used together)") do |v|
|
78
|
-
ENV['PB_CLIENT_TYPE'] = 'Zmq'
|
79
|
-
ENV['PB_SERVER_TYPE'] = 'Zmq'
|
80
|
-
|
81
|
-
server.runner = ::Protobuf::Rpc::ZmqRunner
|
82
|
-
end
|
83
|
-
|
84
|
-
opts.on("--[no-]pre-cache-definitions", "Enable/Disable Message class pre-caching") do |v|
|
85
|
-
server.pre_cache_definitions = v
|
86
|
-
end
|
87
|
-
|
88
|
-
opts.on("--[no-]gc-pause-request", "Enable/Disable GC pause during request.") do |v|
|
89
|
-
server.gc_pause_during_request = v
|
90
|
-
end
|
91
|
-
|
92
|
-
opts.on("--[no-]gc-pause-serialization", "Enable/Disable GC pause during serialization.") do |v|
|
93
|
-
server.gc_pause_during_serialization = v
|
94
|
-
end
|
95
|
-
|
96
|
-
opts.on("-d", "--[no-]debug", "Debug Mode. Override log level to DEBUG.") do |v|
|
97
|
-
server.debug = v
|
98
|
-
server.level = ::Logger::DEBUG if v === true
|
99
|
-
end
|
100
|
-
|
101
|
-
opts.on("--client-type=PB_CLIENT_TYPE", String, "Client Type to use (Socket or Zmq)") do |v|
|
102
|
-
ENV['PB_CLIENT_TYPE'] = v
|
103
|
-
end
|
104
|
-
|
105
|
-
opts.on("--server-type=PB_SERVER_TYPE", String, "Server Type to use (Socket or Zmq)") do |v|
|
106
|
-
ENV['PB_SERVER_TYPE'] = v
|
107
|
-
end
|
108
|
-
|
109
|
-
opts.separator ""
|
110
|
-
opts.separator "Common options:"
|
111
|
-
|
112
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
113
|
-
puts opts
|
114
|
-
exit
|
115
|
-
end
|
116
|
-
|
117
|
-
opts.on_tail("--version", "Show version") do
|
118
|
-
puts ::Protobuf::VERSION
|
119
|
-
exit
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
parser.parse!
|
124
|
-
|
125
|
-
# Used to ensure we set the PB_CLIENT_TYPE and PB_SERVER_TYPE to the same thing
|
126
|
-
# if one of them is set to Zmq
|
127
|
-
if(ENV['PB_CLIENT_TYPE'] =~ /zmq/i)
|
128
|
-
# make server and client types the same if we're using Zmq
|
129
|
-
ENV['PB_SERVER_TYPE'] = ENV['PB_CLIENT_TYPE']
|
130
|
-
server.runner = ::Protobuf::Rpc::ZmqRunner
|
131
|
-
elsif(ENV['PB_SERVER_TYPE'] =~ /zmq/i)
|
132
|
-
# make server and client types the same if we're using Zmq
|
133
|
-
ENV['PB_CLIENT_TYPE'] = ENV['PB_SERVER_TYPE']
|
134
|
-
server.runner = ::Protobuf::Rpc::ZmqRunner
|
135
|
-
elsif(ENV['PB_SERVER_TYPE'] =~ /socket/i)
|
136
|
-
server.runner = ::Protobuf::Rpc::SocketRunner
|
137
|
-
end
|
138
|
-
|
139
|
-
##
|
140
|
-
# Setup GC settings
|
141
|
-
#
|
142
|
-
::Protobuf::Rpc::GC_PAUSE_REQUEST = server.gc_pause_during_request
|
143
|
-
# If we pause during request we don't need to pause in serialization
|
144
|
-
::Protobuf::Rpc::GC_PAUSE_SERIALIZATION = (!server.gc_pause_during_request && server.gc_pause_during_serialization)
|
145
|
-
|
146
|
-
# protobuf.rb picks up PB_CLIENT_TYPE and PB_SERVER_TYPE and does something
|
147
|
-
# useful with them
|
148
|
-
require 'protobuf'
|
149
|
-
|
150
|
-
[:INT, :QUIT, :TERM].each do |sig|
|
151
|
-
trap(sig) do
|
152
|
-
server.stopped_during_startup = true
|
153
|
-
server.runner.stop
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
begin
|
158
|
-
if ARGV.empty?
|
159
|
-
puts 'You must specify an app file to use.'
|
160
|
-
puts parser.help
|
161
|
-
exit
|
162
|
-
else
|
163
|
-
server.app = ARGV.pop
|
164
|
-
raise 'Invalid app file specified (%s).' % server.app unless File.exists?(server.app)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Configure the ::Protobuf::Logger
|
168
|
-
::Protobuf::Logger.configure(:file => server.log, :level => server.debug ? ::Logger::DEBUG : server.level)
|
169
|
-
|
170
|
-
# Output the server opts
|
171
|
-
::Protobuf::Logger.debug { 'Debugging options:' }
|
172
|
-
::Protobuf::Logger.debug { server.inspect }
|
173
|
-
|
174
|
-
# Set the name of the process
|
175
|
-
$0 = 'rpc_server %s:%d %s' % [server.host, server.port, server.app]
|
176
|
-
|
177
|
-
# Require the given application file
|
178
|
-
require server.app unless server.stopped_during_startup
|
179
|
-
|
180
|
-
if server.pre_cache_definitions && !server.stopped_during_startup
|
181
|
-
::Protobuf::Message.pre_cache_class_definitions
|
182
|
-
end
|
183
|
-
|
184
|
-
server.runner.run(server) unless server.stopped_during_startup
|
185
|
-
rescue
|
186
|
-
msg = 'ERROR: RPC Server failed to start. %s' % $!.inspect
|
187
|
-
$stderr.puts(msg, *($!.backtrace))
|
188
|
-
::Protobuf::Logger.error { msg }
|
189
|
-
::Protobuf::Logger.error { $!.backtrace.join("\n") }
|
190
|
-
exit 1
|
191
|
-
end
|
data/bin/rprotoc
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ffi'
|
5
|
+
|
6
|
+
GENERATOR_FILE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "ruby_generator.so"))
|
7
|
+
unless File.exists?(GENERATOR_FILE_PATH)
|
8
|
+
$stdout << <<-WARNING
|
9
|
+
Cannot locate shared object to plugin to protocol buffers generator.
|
10
|
+
Thought the file would be located at #{GENERATOR_FILE_PATH}
|
11
|
+
|
12
|
+
If you are running on Windows you should compile protocol buffer
|
13
|
+
definitions on another VM and then use those definitions locally.
|
14
|
+
|
15
|
+
Only the compiler is restricted by this. The definitions should work without issue.
|
16
|
+
WARNING
|
17
|
+
$stdout << $/
|
4
18
|
|
5
|
-
if File.directory?("#{File.dirname(__FILE__)}/../lib")
|
6
|
-
$: << "#{File.dirname(__FILE__)}/../lib"
|
7
|
-
else
|
8
|
-
require 'rubygems'
|
9
|
-
gem 'protobuf'
|
10
|
-
end
|
11
|
-
require 'protobuf'
|
12
|
-
require 'protobuf/version'
|
13
|
-
require 'protobuf/compiler/compiler'
|
14
|
-
|
15
|
-
::Version = Protobuf::VERSION
|
16
|
-
|
17
|
-
options = {
|
18
|
-
:proto_path => '.',
|
19
|
-
:out => '.',
|
20
|
-
}
|
21
|
-
opts = OptionParser.new("#{$0} [OPTIONS] PROTO_FILE")
|
22
|
-
opts.on('-p', '--proto_path <PATH>', 'Specify the directory in which to search for imports. The current directory is default.'){|v| options[:proto_path] = v}
|
23
|
-
opts.on('-o', '--out <OUT_DIR>', 'Specify the directory in which Ruby source file is generated. The current directory is default.'){|v| options[:out] = v}
|
24
|
-
opts.on_tail('-v', '--version', 'Show version.'){ puts(opts.ver); exit }
|
25
|
-
opts.on_tail('-h', '--help', 'Show this message.'){ puts(opts.help); exit }
|
26
|
-
|
27
|
-
begin
|
28
|
-
opts.order!
|
29
|
-
rescue OptionParser::ParseError
|
30
|
-
$stderr.puts $!.to_s
|
31
19
|
exit 1
|
32
20
|
end
|
33
21
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
module Protobuf
|
23
|
+
module RProtoC
|
24
|
+
extend FFI::Library
|
25
|
+
ffi_lib ::GENERATOR_FILE_PATH
|
26
|
+
attach_function :_rprotoc_extern, [:int, :pointer], :int32
|
27
|
+
|
28
|
+
def self.compile_proto(args)
|
29
|
+
GC.disable # Don't want strings to be GC'd while protoc has them
|
30
|
+
args = args.dup
|
31
|
+
args.unshift("rprotoc")
|
32
|
+
args << "--help" if args.size == 1
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
ptr_params = []
|
35
|
+
args.each do |param|
|
36
|
+
ptr_params << ::FFI::MemoryPointer.from_string(param.dup)
|
37
|
+
end
|
38
|
+
ptr_params << nil
|
39
|
+
|
40
|
+
argv = ::FFI::MemoryPointer.new(:pointer, ptr_params.size)
|
41
|
+
ptr_params.each_with_index do |param_pointer, index|
|
42
|
+
argv[index].put_pointer(0, param_pointer)
|
43
|
+
end
|
44
|
+
|
45
|
+
self._rprotoc_extern(ptr_params.compact.size, argv)
|
46
|
+
ensure
|
47
|
+
GC.enable
|
48
|
+
end
|
42
49
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
50
|
+
end
|
51
|
+
|
52
|
+
::Protobuf::RProtoC.compile_proto(ARGV)
|
data/examples/addressbook.pb.rb
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
# }
|
27
27
|
|
28
28
|
require 'protobuf/message/message'
|
29
|
-
require 'protobuf/
|
29
|
+
require 'protobuf/enum'
|
30
30
|
require 'protobuf/message/extend'
|
31
31
|
|
32
32
|
module Tutorial
|
@@ -52,4 +52,4 @@ module Tutorial
|
|
52
52
|
defined_in __FILE__
|
53
53
|
repeated :Person, :person, 1
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
data/ext/Makefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
all: \
|
2
|
+
RubyGenerator.h \
|
3
|
+
RubyGenerator.cpp \
|
4
|
+
main.cpp
|
5
|
+
g++ -Wall -I/code/src/utilities/protobuf-2.4.1/src -lprotoc -lprotobuf -lpthread -o protoc-ruby RubyGenerator.cpp main.cpp
|
6
|
+
|
7
|
+
test:
|
8
|
+
rm -rf test/out/*
|
9
|
+
./protoc-ruby --proto_path=defs --ruby_out=out defs/atlas/util.proto defs/atlas/newman/*.proto
|
10
|
+
|
11
|
+
.PHONY: all test
|
@@ -0,0 +1,142 @@
|
|
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
|
+
// Defines the abstract interface implemented by each of the language-specific
|
36
|
+
// code generators.
|
37
|
+
|
38
|
+
#ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__
|
39
|
+
#define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__
|
40
|
+
|
41
|
+
#include <google/protobuf/stubs/common.h>
|
42
|
+
#include <string>
|
43
|
+
#include <vector>
|
44
|
+
#include <utility>
|
45
|
+
|
46
|
+
namespace google {
|
47
|
+
namespace protobuf {
|
48
|
+
|
49
|
+
namespace io { class ZeroCopyOutputStream; }
|
50
|
+
class FileDescriptor;
|
51
|
+
|
52
|
+
namespace compiler {
|
53
|
+
|
54
|
+
// Defined in this file.
|
55
|
+
class CodeGenerator;
|
56
|
+
class GeneratorContext;
|
57
|
+
|
58
|
+
// The abstract interface to a class which generates code implementing a
|
59
|
+
// particular proto file in a particular language. A number of these may
|
60
|
+
// be registered with CommandLineInterface to support various languages.
|
61
|
+
class LIBPROTOC_EXPORT CodeGenerator {
|
62
|
+
public:
|
63
|
+
inline CodeGenerator() {}
|
64
|
+
virtual ~CodeGenerator();
|
65
|
+
|
66
|
+
// Generates code for the given proto file, generating one or more files in
|
67
|
+
// the given output directory.
|
68
|
+
//
|
69
|
+
// A parameter to be passed to the generator can be specified on the
|
70
|
+
// command line. This is intended to be used by Java and similar languages
|
71
|
+
// to specify which specific class from the proto file is to be generated,
|
72
|
+
// though it could have other uses as well. It is empty if no parameter was
|
73
|
+
// given.
|
74
|
+
//
|
75
|
+
// Returns true if successful. Otherwise, sets *error to a description of
|
76
|
+
// the problem (e.g. "invalid parameter") and returns false.
|
77
|
+
virtual bool Generate(const FileDescriptor* file,
|
78
|
+
const string& parameter,
|
79
|
+
GeneratorContext* generator_context,
|
80
|
+
string* error) const = 0;
|
81
|
+
|
82
|
+
private:
|
83
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator);
|
84
|
+
};
|
85
|
+
|
86
|
+
// CodeGenerators generate one or more files in a given directory. This
|
87
|
+
// abstract interface represents the directory to which the CodeGenerator is
|
88
|
+
// to write and other information about the context in which the Generator
|
89
|
+
// runs.
|
90
|
+
class LIBPROTOC_EXPORT GeneratorContext {
|
91
|
+
public:
|
92
|
+
inline GeneratorContext() {}
|
93
|
+
virtual ~GeneratorContext();
|
94
|
+
|
95
|
+
// Opens the given file, truncating it if it exists, and returns a
|
96
|
+
// ZeroCopyOutputStream that writes to the file. The caller takes ownership
|
97
|
+
// of the returned object. This method never fails (a dummy stream will be
|
98
|
+
// returned instead).
|
99
|
+
//
|
100
|
+
// The filename given should be relative to the root of the source tree.
|
101
|
+
// E.g. the C++ generator, when generating code for "foo/bar.proto", will
|
102
|
+
// generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that
|
103
|
+
// "foo/" is included in these filenames. The filename is not allowed to
|
104
|
+
// contain "." or ".." components.
|
105
|
+
virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0;
|
106
|
+
|
107
|
+
// Creates a ZeroCopyOutputStream which will insert code into the given file
|
108
|
+
// at the given insertion point. See plugin.proto (plugin.pb.h) for more
|
109
|
+
// information on insertion points. The default implementation
|
110
|
+
// assert-fails -- it exists only for backwards-compatibility.
|
111
|
+
//
|
112
|
+
// WARNING: This feature is currently EXPERIMENTAL and is subject to change.
|
113
|
+
virtual io::ZeroCopyOutputStream* OpenForInsert(
|
114
|
+
const string& filename, const string& insertion_point);
|
115
|
+
|
116
|
+
// Returns a vector of FileDescriptors for all the files being compiled
|
117
|
+
// in this run. Useful for languages, such as Go, that treat files
|
118
|
+
// differently when compiled as a set rather than individually.
|
119
|
+
virtual void ListParsedFiles(vector<const FileDescriptor*>* output);
|
120
|
+
|
121
|
+
private:
|
122
|
+
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext);
|
123
|
+
};
|
124
|
+
|
125
|
+
// The type GeneratorContext was once called OutputDirectory. This typedef
|
126
|
+
// provides backward compatibility.
|
127
|
+
typedef GeneratorContext OutputDirectory;
|
128
|
+
|
129
|
+
// Several code generators treat the parameter argument as holding a
|
130
|
+
// list of options separated by commas. This helper function parses
|
131
|
+
// a set of comma-delimited name/value pairs: e.g.,
|
132
|
+
// "foo=bar,baz,qux=corge"
|
133
|
+
// parses to the pairs:
|
134
|
+
// ("foo", "bar"), ("baz", ""), ("qux", "corge")
|
135
|
+
extern void ParseGeneratorParameter(const string&,
|
136
|
+
vector<pair<string, string> >*);
|
137
|
+
|
138
|
+
} // namespace compiler
|
139
|
+
} // namespace protobuf
|
140
|
+
|
141
|
+
} // namespace google
|
142
|
+
#endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__
|