protobuffy 3.6.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +67 -0
- data/.rubocop_todo.yml +145 -0
- data/.travis.yml +25 -5
- data/CHANGES.md +55 -0
- data/CONTRIBUTING.md +1 -1
- data/LICENSE.txt +17 -9
- data/README.md +13 -12
- data/Rakefile +15 -11
- data/bin/protoc-gen-ruby +8 -3
- data/bin/rpc_server +1 -0
- data/examples/lib/example/reverse-client.rb +2 -2
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +57 -53
- data/lib/protobuf/cli.rb +94 -74
- data/lib/protobuf/code_generator.rb +60 -9
- data/lib/protobuf/decoder.rb +19 -65
- data/lib/protobuf/deprecation.rb +117 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
- data/lib/protobuf/encoder.rb +13 -53
- data/lib/protobuf/enum.rb +58 -63
- data/lib/protobuf/field.rb +4 -4
- data/lib/protobuf/field/base_field.rb +101 -173
- data/lib/protobuf/field/bool_field.rb +17 -11
- data/lib/protobuf/field/bytes_field.rb +21 -35
- data/lib/protobuf/field/double_field.rb +0 -1
- data/lib/protobuf/field/enum_field.rb +23 -22
- data/lib/protobuf/field/field_array.rb +5 -4
- data/lib/protobuf/field/fixed32_field.rb +1 -1
- data/lib/protobuf/field/fixed64_field.rb +0 -1
- data/lib/protobuf/field/float_field.rb +4 -1
- data/lib/protobuf/field/int32_field.rb +0 -1
- data/lib/protobuf/field/int64_field.rb +0 -1
- data/lib/protobuf/field/integer_field.rb +0 -1
- data/lib/protobuf/field/message_field.rb +13 -28
- data/lib/protobuf/field/sfixed32_field.rb +0 -1
- data/lib/protobuf/field/sfixed64_field.rb +0 -1
- data/lib/protobuf/field/signed_integer_field.rb +0 -1
- data/lib/protobuf/field/sint32_field.rb +0 -1
- data/lib/protobuf/field/sint64_field.rb +0 -1
- data/lib/protobuf/field/string_field.rb +2 -4
- data/lib/protobuf/field/uint32_field.rb +0 -1
- data/lib/protobuf/field/uint64_field.rb +0 -1
- data/lib/protobuf/field/varint_field.rb +30 -13
- data/lib/protobuf/generators/base.rb +30 -16
- data/lib/protobuf/generators/enum_generator.rb +6 -9
- data/lib/protobuf/generators/extension_generator.rb +1 -2
- data/lib/protobuf/generators/field_generator.rb +25 -13
- data/lib/protobuf/generators/file_generator.rb +157 -35
- data/lib/protobuf/generators/group_generator.rb +22 -17
- data/lib/protobuf/generators/message_generator.rb +13 -14
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +12 -13
- data/lib/protobuf/generators/service_generator.rb +2 -3
- data/lib/protobuf/http.rb +2 -2
- data/lib/protobuf/lifecycle.rb +20 -33
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +114 -47
- data/lib/protobuf/message/fields.rb +170 -88
- data/lib/protobuf/message/serialization.rb +19 -18
- data/lib/protobuf/optionable.rb +53 -6
- data/lib/protobuf/rpc/buffer.rb +18 -19
- data/lib/protobuf/rpc/client.rb +22 -50
- data/lib/protobuf/rpc/connectors/base.rb +177 -12
- data/lib/protobuf/rpc/connectors/http.rb +14 -9
- data/lib/protobuf/rpc/connectors/ping.rb +89 -0
- data/lib/protobuf/rpc/connectors/socket.rb +13 -8
- data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
- data/lib/protobuf/rpc/env.rb +12 -12
- data/lib/protobuf/rpc/error.rb +3 -3
- data/lib/protobuf/rpc/error/client_error.rb +4 -4
- data/lib/protobuf/rpc/error/server_error.rb +9 -9
- data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
- data/lib/protobuf/rpc/middleware/logger.rb +8 -4
- data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
- data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
- data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
- data/lib/protobuf/rpc/rpc.pb.rb +4 -1
- data/lib/protobuf/rpc/server.rb +1 -1
- data/lib/protobuf/rpc/servers/http/server.rb +19 -17
- data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
- data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
- data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
- data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
- data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
- data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
- data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
- data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
- data/lib/protobuf/rpc/service.rb +21 -27
- data/lib/protobuf/rpc/service_directory.rb +43 -27
- data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
- data/lib/protobuf/rpc/service_filters.rb +32 -55
- data/lib/protobuf/rpc/stat.rb +4 -8
- data/lib/protobuf/socket.rb +1 -2
- data/lib/protobuf/tasks/compile.rake +3 -4
- data/lib/protobuf/varint.rb +9 -0
- data/lib/protobuf/varint_pure.rb +13 -0
- data/lib/protobuf/version.rb +1 -1
- data/lib/protobuf/zmq.rb +2 -2
- data/proto/google/protobuf/descriptor.proto +190 -31
- data/protobuffy.gemspec +30 -17
- data/spec/benchmark/tasks.rb +27 -19
- data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
- data/spec/encoding/all_types_spec.rb +96 -84
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/code_generator_spec.rb +38 -0
- data/spec/functional/socket_server_spec.rb +15 -15
- data/spec/functional/zmq_server_spec.rb +29 -27
- data/spec/lib/protobuf/cli_spec.rb +82 -67
- data/spec/lib/protobuf/code_generator_spec.rb +37 -10
- data/spec/lib/protobuf/enum_spec.rb +77 -46
- data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field_spec.rb +4 -6
- data/spec/lib/protobuf/generators/base_spec.rb +80 -13
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
- data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
- data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
- data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
- data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
- data/spec/lib/protobuf/message_spec.rb +578 -79
- data/spec/lib/protobuf/optionable_spec.rb +202 -26
- data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
- data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
- data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
- data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
- data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
- data/spec/lib/protobuf/varint_spec.rb +29 -0
- data/spec/lib/protobuf_spec.rb +55 -28
- data/spec/spec_helper.rb +12 -27
- data/spec/support/all.rb +0 -1
- data/spec/support/packed_field.rb +4 -3
- data/spec/support/{test → protos}/all_types.data.bin +0 -0
- data/spec/support/{test → protos}/all_types.data.txt +0 -0
- data/spec/support/{test → protos}/enum.pb.rb +8 -4
- data/spec/support/{test → protos}/enum.proto +4 -1
- data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
- data/spec/support/protos/google_unittest.bin +0 -0
- data/spec/support/protos/google_unittest.pb.rb +798 -0
- data/spec/support/{test → protos}/google_unittest.proto +237 -66
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +55 -0
- data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
- data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
- data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
- data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
- data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
- data/spec/support/{test → protos}/resource.pb.rb +47 -11
- data/spec/support/{test → protos}/resource.proto +24 -1
- data/spec/support/resource_service.rb +23 -0
- data/spec/support/server.rb +32 -61
- metadata +119 -59
- data/lib/protobuf/deprecator.rb +0 -42
- data/lib/protobuf/logger.rb +0 -93
- data/lib/protobuf/rpc/connector.rb +0 -21
- data/lib/protobuf/rpc/connectors/common.rb +0 -172
- data/spec/data/data.bin +0 -3
- data/spec/data/types.bin +0 -0
- data/spec/lib/protobuf/logger_spec.rb +0 -145
- data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
- data/spec/support/test/defaults.pb.rb +0 -25
- data/spec/support/test/defaults.proto +0 -9
- data/spec/support/test/extended.pb.rb +0 -22
- data/spec/support/test/extended.proto +0 -10
- data/spec/support/test/google_unittest.pb.rb +0 -543
- data/spec/support/test/google_unittest_import.pb.rb +0 -37
- data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
- data/spec/support/test/resource_service.rb +0 -26
- data/spec/support/tolerance_matcher.rb +0 -40
data/protobuffy.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
2
|
+
$LOAD_PATH.push ::File.expand_path("../lib", __FILE__)
|
3
3
|
require "protobuf/version"
|
4
4
|
|
5
5
|
::Gem::Specification.new do |s|
|
6
6
|
s.name = 'protobuffy'
|
7
7
|
s.version = ::Protobuf::VERSION
|
8
8
|
s.date = ::Time.now.strftime('%Y-%m-%d')
|
9
|
-
s.license = '
|
9
|
+
s.license = 'MIT'
|
10
10
|
|
11
|
-
s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison', 'R. Tyler Croy'
|
11
|
+
s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison', 'R. Tyler Croy']
|
12
12
|
s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com', 'liveh2o@gmail.com', 'tyler@monkeypox.org']
|
13
13
|
s.homepage = 'https://github.com/lookout/protobuffy'
|
14
14
|
s.summary = "Google Protocol Buffers serialization and RPC implementation for Ruby."
|
@@ -19,26 +19,39 @@ require "protobuf/version"
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
s.add_dependency 'activesupport', '< 5'
|
26
|
-
end
|
27
|
-
|
22
|
+
# Hack, as Rails 5 requires Ruby version >= 2.2.2.
|
23
|
+
active_support_max_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
|
24
|
+
s.add_dependency "activesupport", '>= 3.2', active_support_max_version
|
28
25
|
s.add_dependency 'middleware'
|
29
|
-
s.add_dependency 'multi_json', '~> 1.0'
|
30
26
|
s.add_dependency 'thor'
|
31
|
-
s.add_dependency '
|
27
|
+
s.add_dependency 'thread_safe'
|
32
28
|
|
29
|
+
s.add_development_dependency 'ffi-rzmq'
|
30
|
+
s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses
|
33
31
|
s.add_development_dependency 'rack', '~> 1.0'
|
34
32
|
s.add_development_dependency 'faraday'
|
35
|
-
s.add_development_dependency '
|
36
|
-
s.add_development_dependency
|
37
|
-
s.add_development_dependency
|
38
|
-
s.add_development_dependency 'rspec', '2.99.0'
|
33
|
+
s.add_development_dependency 'rspec', '>= 3.0'
|
34
|
+
s.add_development_dependency "rubocop", "~> 0.38.0"
|
35
|
+
s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984
|
39
36
|
s.add_development_dependency 'simplecov'
|
40
|
-
s.add_development_dependency 'yard'
|
41
37
|
s.add_development_dependency 'timecop'
|
38
|
+
s.add_development_dependency 'yard'
|
39
|
+
|
40
|
+
# debuggers only work in MRI
|
41
|
+
if RUBY_ENGINE.to_sym == :ruby
|
42
|
+
# we don't support MRI < 1.9.3
|
43
|
+
pry_debugger = if RUBY_VERSION < '2.0.0'
|
44
|
+
'pry-debugger'
|
45
|
+
else
|
46
|
+
'pry-byebug'
|
47
|
+
end
|
48
|
+
|
49
|
+
s.add_development_dependency pry_debugger
|
50
|
+
s.add_development_dependency 'pry-stack_explorer'
|
42
51
|
|
43
|
-
|
52
|
+
s.add_development_dependency 'varint'
|
53
|
+
s.add_development_dependency 'ruby-prof'
|
54
|
+
else
|
55
|
+
s.add_development_dependency 'pry'
|
56
|
+
end
|
44
57
|
end
|
data/spec/benchmark/tasks.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'benchmark'
|
2
|
+
require 'protobuf'
|
2
3
|
require 'protobuf/socket'
|
3
4
|
require 'support/all'
|
4
|
-
require '
|
5
|
+
require 'spec_helper'
|
6
|
+
require SUPPORT_PATH.join('resource_service')
|
5
7
|
|
6
8
|
case RUBY_ENGINE.to_sym
|
7
9
|
when :ruby
|
@@ -15,8 +17,8 @@ end
|
|
15
17
|
# Including a way to turn on debug logger for spec runs
|
16
18
|
if ENV["DEBUG"]
|
17
19
|
puts 'debugging'
|
18
|
-
debug_log = File.expand_path('
|
19
|
-
Protobuf::
|
20
|
+
debug_log = File.expand_path('../../../debug_bench.log', __FILE__)
|
21
|
+
Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG)
|
20
22
|
end
|
21
23
|
|
22
24
|
namespace :benchmark do
|
@@ -34,12 +36,14 @@ namespace :benchmark do
|
|
34
36
|
def sock_client_sock_server(number_tests, test_length, global_bench = nil)
|
35
37
|
load "protobuf/socket.rb"
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
40
|
+
|
41
|
+
StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do
|
42
|
+
client = ::Test::ResourceService.client(:port => port)
|
39
43
|
|
40
44
|
benchmark_wrapper(global_bench) do |bench|
|
41
45
|
bench.report("SS / SC") do
|
42
|
-
(
|
46
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
@@ -47,26 +51,28 @@ namespace :benchmark do
|
|
47
51
|
|
48
52
|
def zmq_client_zmq_server(number_tests, test_length, global_bench = nil)
|
49
53
|
load "protobuf/zmq.rb"
|
50
|
-
|
51
|
-
|
54
|
+
|
55
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
56
|
+
|
57
|
+
StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do
|
58
|
+
client = ::Test::ResourceService.client(:port => port)
|
52
59
|
|
53
60
|
benchmark_wrapper(global_bench) do |bench|
|
54
61
|
bench.report("ZS / ZC") do
|
55
|
-
(
|
62
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
56
63
|
end
|
57
64
|
end
|
58
|
-
server.stop
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
62
68
|
desc "benchmark ZMQ client with ZMQ server"
|
63
|
-
task :zmq_client_zmq_server, [:number, :length] do |
|
69
|
+
task :zmq_client_zmq_server, [:number, :length] do |_task, args|
|
64
70
|
args.with_defaults(:number => 1000, :length => 100)
|
65
71
|
zmq_client_zmq_server(args[:number], args[:length])
|
66
72
|
end
|
67
73
|
|
68
74
|
desc "benchmark ZMQ client with ZMQ server and profile"
|
69
|
-
task :zmq_profile, [:number, :length, :profile_output] do |
|
75
|
+
task :zmq_profile, [:number, :length, :profile_output] do |_task, args|
|
70
76
|
args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}")
|
71
77
|
profile_code(args[:profile_output]) do
|
72
78
|
zmq_client_zmq_server(args[:number], args[:length])
|
@@ -76,22 +82,22 @@ namespace :benchmark do
|
|
76
82
|
end
|
77
83
|
|
78
84
|
desc "benchmark Protobuf Message #new"
|
79
|
-
task :profile_protobuf_new, [:number, :profile_output] do |
|
85
|
+
task :profile_protobuf_new, [:number, :profile_output] do |_task, args|
|
80
86
|
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
81
87
|
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
82
88
|
profile_code(args[:profile_output]) do
|
83
|
-
args[:number].
|
89
|
+
Integer(args[:number]).times { Test::Resource.new(create_params) }
|
84
90
|
end
|
85
91
|
|
86
92
|
puts args[:profile_output]
|
87
93
|
end
|
88
94
|
|
89
95
|
desc "benchmark Protobuf Message #serialize"
|
90
|
-
task :profile_protobuf_serialize, [:number, :profile_output] do |
|
96
|
+
task :profile_protobuf_serialize, [:number, :profile_output] do |_task, args|
|
91
97
|
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
92
98
|
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
93
99
|
profile_code(args[:profile_output]) do
|
94
|
-
args[:number].
|
100
|
+
Integer(args[:number]).times { Test::Resource.decode(Test::Resource.new(create_params).serialize) }
|
95
101
|
end
|
96
102
|
|
97
103
|
puts args[:profile_output]
|
@@ -101,7 +107,9 @@ namespace :benchmark do
|
|
101
107
|
case RUBY_ENGINE.to_sym
|
102
108
|
when :ruby
|
103
109
|
profile_data = RubyProf.profile(&block)
|
104
|
-
|
110
|
+
::File.open(output, "w") do |output_file|
|
111
|
+
RubyProf::FlatPrinter.new(profile_data).print(output_file)
|
112
|
+
end
|
105
113
|
when :rbx
|
106
114
|
profiler = Rubinius::Profiler::Instrumenter.new
|
107
115
|
profiler.profile(false, &block)
|
@@ -117,13 +125,13 @@ namespace :benchmark do
|
|
117
125
|
end
|
118
126
|
|
119
127
|
desc "benchmark Socket client with Socket server"
|
120
|
-
task :sock_client_sock_server, [:number, :length] do |
|
128
|
+
task :sock_client_sock_server, [:number, :length] do |_task, args|
|
121
129
|
args.with_defaults(:number => 1000, :length => 100)
|
122
130
|
sock_client_sock_server(args[:number], args[:length])
|
123
131
|
end
|
124
132
|
|
125
133
|
desc "benchmark server performance"
|
126
|
-
task :servers, [:number, :length] do |
|
134
|
+
task :servers, [:number, :length] do |_task, args|
|
127
135
|
args.with_defaults(:number => 1000, :length => 100)
|
128
136
|
|
129
137
|
Benchmark.bm(10) do |bench|
|
@@ -2,17 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'protobuf/code_generator'
|
4
4
|
|
5
|
-
describe 'protoc-gen-ruby' do
|
5
|
+
RSpec.describe 'protoc-gen-ruby' do
|
6
6
|
let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) }
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
|
7
|
+
let(:package) { 'test' }
|
8
|
+
let(:request_bytes) do
|
9
|
+
::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(
|
10
|
+
:proto_file => [{ :package => package }]
|
11
|
+
)
|
12
|
+
end
|
10
13
|
|
11
14
|
it 'reads the serialized request bytes and outputs serialized response bytes' do
|
12
15
|
::IO.popen(binpath, 'w+') do |pipe|
|
13
16
|
pipe.write(request_bytes)
|
14
|
-
pipe.read
|
17
|
+
pipe.close_write # needed so we can implicitly read until EOF
|
18
|
+
response_bytes = pipe.read
|
19
|
+
response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(response_bytes)
|
20
|
+
expect(response.file.first.content).to include("module #{package.titleize}")
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
18
|
-
|
@@ -1,91 +1,103 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require PROTOS_PATH.join('google_unittest.pb')
|
2
3
|
|
3
|
-
describe ::Protobuf do
|
4
|
+
RSpec.describe ::Protobuf do
|
4
5
|
it "correctly encodes all types" do
|
5
|
-
message =
|
6
|
-
optional_int32
|
7
|
-
optional_int64
|
8
|
-
optional_uint32
|
9
|
-
optional_uint64
|
10
|
-
optional_sint32
|
11
|
-
optional_sint64
|
12
|
-
optional_fixed32
|
13
|
-
optional_fixed64
|
14
|
-
optional_sfixed32
|
15
|
-
optional_sfixed64
|
16
|
-
optional_float
|
17
|
-
optional_double
|
18
|
-
optional_bool
|
19
|
-
optional_string
|
20
|
-
optional_bytes
|
21
|
-
optional_nested_message
|
22
|
-
optional_foreign_message
|
23
|
-
optional_import_message
|
24
|
-
optional_nested_enum
|
25
|
-
optional_foreign_enum
|
26
|
-
optional_import_enum
|
27
|
-
optional_string_piece
|
28
|
-
optional_cord
|
29
|
-
optional_public_import_message
|
30
|
-
optional_lazy_message
|
31
|
-
repeated_int32
|
32
|
-
repeated_int64
|
33
|
-
repeated_uint32
|
34
|
-
repeated_uint64
|
35
|
-
repeated_sint32
|
36
|
-
repeated_sint64
|
37
|
-
repeated_fixed32
|
38
|
-
repeated_fixed64
|
39
|
-
repeated_sfixed32
|
40
|
-
repeated_sfixed64
|
41
|
-
repeated_float
|
42
|
-
repeated_double
|
43
|
-
repeated_bool
|
44
|
-
repeated_string
|
45
|
-
repeated_bytes
|
46
|
-
repeated_nested_message
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
6
|
+
message = Protobuf_unittest::TestAllTypes.new(
|
7
|
+
:optional_int32 => 101,
|
8
|
+
:optional_int64 => 102,
|
9
|
+
:optional_uint32 => 103,
|
10
|
+
:optional_uint64 => 104,
|
11
|
+
:optional_sint32 => 105,
|
12
|
+
:optional_sint64 => 106,
|
13
|
+
:optional_fixed32 => 107,
|
14
|
+
:optional_fixed64 => 108,
|
15
|
+
:optional_sfixed32 => 109,
|
16
|
+
:optional_sfixed64 => 110,
|
17
|
+
:optional_float => 111,
|
18
|
+
:optional_double => 112,
|
19
|
+
:optional_bool => true,
|
20
|
+
:optional_string => "115",
|
21
|
+
:optional_bytes => "116",
|
22
|
+
:optional_nested_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 118),
|
23
|
+
:optional_foreign_message => Protobuf_unittest::ForeignMessage.new(:c => 119),
|
24
|
+
:optional_import_message => Protobuf_unittest_import::ImportMessage.new(:d => 120),
|
25
|
+
:optional_nested_enum => Protobuf_unittest::TestAllTypes::NestedEnum::BAZ,
|
26
|
+
:optional_foreign_enum => Protobuf_unittest::ForeignEnum::FOREIGN_BAZ,
|
27
|
+
:optional_import_enum => Protobuf_unittest_import::ImportEnum::IMPORT_BAZ,
|
28
|
+
:optional_string_piece => "124",
|
29
|
+
:optional_cord => "125",
|
30
|
+
:optional_public_import_message => Protobuf_unittest_import::PublicImportMessage.new(:e => 126),
|
31
|
+
:optional_lazy_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 127),
|
32
|
+
:repeated_int32 => [201, 301],
|
33
|
+
:repeated_int64 => [202, 302],
|
34
|
+
:repeated_uint32 => [203, 303],
|
35
|
+
:repeated_uint64 => [204, 304],
|
36
|
+
:repeated_sint32 => [205, 305],
|
37
|
+
:repeated_sint64 => [206, 306],
|
38
|
+
:repeated_fixed32 => [207, 307],
|
39
|
+
:repeated_fixed64 => [208, 308],
|
40
|
+
:repeated_sfixed32 => [209, 309],
|
41
|
+
:repeated_sfixed64 => [210, 310],
|
42
|
+
:repeated_float => [211, 311],
|
43
|
+
:repeated_double => [212, 312],
|
44
|
+
:repeated_bool => [true, false],
|
45
|
+
:repeated_string => ["215", "315"],
|
46
|
+
:repeated_bytes => ["216", "316"],
|
47
|
+
:repeated_nested_message => [
|
48
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 218),
|
49
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 318),
|
50
|
+
],
|
51
|
+
:repeated_foreign_message => [
|
52
|
+
::Protobuf_unittest::ForeignMessage.new(:c => 219),
|
53
|
+
::Protobuf_unittest::ForeignMessage.new(:c => 319),
|
54
|
+
],
|
55
|
+
:repeated_import_message => [
|
56
|
+
::Protobuf_unittest_import::ImportMessage.new(:d => 220),
|
57
|
+
::Protobuf_unittest_import::ImportMessage.new(:d => 320),
|
58
|
+
],
|
59
|
+
:repeated_nested_enum => [
|
60
|
+
::Protobuf_unittest::TestAllTypes::NestedEnum::BAR,
|
61
|
+
::Protobuf_unittest::TestAllTypes::NestedEnum::BAZ,
|
62
|
+
],
|
63
|
+
:repeated_foreign_enum => [
|
64
|
+
::Protobuf_unittest::ForeignEnum::FOREIGN_BAR,
|
65
|
+
::Protobuf_unittest::ForeignEnum::FOREIGN_BAZ,
|
66
|
+
],
|
67
|
+
:repeated_import_enum => [
|
68
|
+
::Protobuf_unittest_import::ImportEnum::IMPORT_BAR,
|
69
|
+
::Protobuf_unittest_import::ImportEnum::IMPORT_BAZ,
|
70
|
+
],
|
71
|
+
:repeated_string_piece => ["224", "324"],
|
72
|
+
:repeated_cord => ["225", "325"],
|
73
|
+
:repeated_lazy_message => [
|
74
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 227),
|
75
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 327),
|
76
|
+
],
|
77
|
+
:default_int32 => 401,
|
78
|
+
:default_int64 => 402,
|
79
|
+
:default_uint32 => 403,
|
80
|
+
:default_uint64 => 404,
|
81
|
+
:default_sint32 => 405,
|
82
|
+
:default_sint64 => 406,
|
83
|
+
:default_fixed32 => 407,
|
84
|
+
:default_fixed64 => 408,
|
85
|
+
:default_sfixed32 => 409,
|
86
|
+
:default_sfixed64 => 410,
|
87
|
+
:default_float => 411,
|
88
|
+
:default_double => 412,
|
89
|
+
:default_bool => false,
|
90
|
+
:default_string => "415",
|
91
|
+
:default_bytes => "416",
|
92
|
+
:default_nested_enum => ::Protobuf_unittest::TestAllTypes::NestedEnum::FOO,
|
93
|
+
:default_foreign_enum => ::Protobuf_unittest::ForeignEnum::FOREIGN_FOO,
|
94
|
+
:default_import_enum => ::Protobuf_unittest_import::ImportEnum::IMPORT_FOO,
|
95
|
+
:default_string_piece => "424",
|
96
|
+
:default_cord => "425"
|
82
97
|
)
|
83
98
|
|
84
|
-
data_file_path =
|
85
|
-
data = File.open(data_file_path, 'rb')
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
data.should eq message.serialize_to_string
|
99
|
+
data_file_path = PROTOS_PATH.join('all_types.data.bin')
|
100
|
+
data = File.open(data_file_path, 'rb', &:read)
|
101
|
+
expect(data).to eq(message.serialize_to_string)
|
90
102
|
end
|
91
103
|
end
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require SUPPORT_PATH.join('resource_service')
|
3
|
+
|
4
|
+
RSpec.describe 'works through class inheritance' do
|
5
|
+
module Corp
|
6
|
+
module Protobuf
|
7
|
+
class Error < ::Protobuf::Message
|
8
|
+
required :string, :foo, 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
module Corp
|
13
|
+
class ErrorHandler < Corp::Protobuf::Error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:args) { { :foo => 'bar' } }
|
18
|
+
let(:parent_class) { Corp::Protobuf::Error }
|
19
|
+
let(:inherited_class) { Corp::ErrorHandler }
|
20
|
+
|
21
|
+
specify '#encode' do
|
22
|
+
expected_result = "\n\x03bar"
|
23
|
+
expected_result.force_encoding(Encoding::BINARY)
|
24
|
+
expect(parent_class.new(args).encode).to eq(expected_result)
|
25
|
+
expect(inherited_class.new(args).encode).to eq(expected_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
specify '#to_hash' do
|
29
|
+
expect(parent_class.new(args).to_hash).to eq(args)
|
30
|
+
expect(inherited_class.new(args).to_hash).to eq(args)
|
31
|
+
end
|
32
|
+
|
33
|
+
specify '#to_json' do
|
34
|
+
expect(parent_class.new(args).to_json).to eq(args.to_json)
|
35
|
+
expect(inherited_class.new(args).to_json).to eq(args.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
specify '.encode' do
|
39
|
+
expected_result = "\n\x03bar"
|
40
|
+
expected_result.force_encoding(Encoding::BINARY)
|
41
|
+
expect(parent_class.encode(args)).to eq(expected_result)
|
42
|
+
expect(inherited_class.encode(args)).to eq(expected_result)
|
43
|
+
end
|
44
|
+
|
45
|
+
specify '.decode' do
|
46
|
+
raw_value = "\n\x03bar"
|
47
|
+
raw_value.force_encoding(Encoding::BINARY)
|
48
|
+
expect(parent_class.decode(raw_value).to_hash).to eq(args)
|
49
|
+
expect(inherited_class.decode(raw_value).to_hash).to eq(args)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|