protobuf 3.7.0.pre2 → 3.7.0.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -1
  3. data/.rubocop_todo.yml +7 -1
  4. data/.travis.yml +8 -1
  5. data/CHANGES.md +25 -1
  6. data/bin/protoc-gen-ruby +2 -2
  7. data/lib/protobuf/cli.rb +29 -17
  8. data/lib/protobuf/code_generator.rb +49 -1
  9. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +9 -1
  10. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +14 -1
  11. data/lib/protobuf/encoder.rb +2 -2
  12. data/lib/protobuf/enum.rb +3 -3
  13. data/lib/protobuf/field/base_field.rb +27 -19
  14. data/lib/protobuf/field/bool_field.rb +10 -8
  15. data/lib/protobuf/field/bytes_field.rb +14 -6
  16. data/lib/protobuf/field/float_field.rb +2 -0
  17. data/lib/protobuf/field/string_field.rb +10 -0
  18. data/lib/protobuf/field/varint_field.rb +12 -2
  19. data/lib/protobuf/generators/base.rb +29 -14
  20. data/lib/protobuf/generators/enum_generator.rb +4 -7
  21. data/lib/protobuf/generators/field_generator.rb +17 -4
  22. data/lib/protobuf/generators/file_generator.rb +121 -10
  23. data/lib/protobuf/generators/group_generator.rb +9 -3
  24. data/lib/protobuf/generators/message_generator.rb +8 -2
  25. data/lib/protobuf/generators/option_generator.rb +17 -0
  26. data/lib/protobuf/generators/printable.rb +2 -2
  27. data/lib/protobuf/generators/service_generator.rb +27 -3
  28. data/lib/protobuf/lifecycle.rb +1 -1
  29. data/lib/protobuf/message/fields.rb +13 -15
  30. data/lib/protobuf/message/serialization.rb +9 -9
  31. data/lib/protobuf/message.rb +23 -29
  32. data/lib/protobuf/optionable.rb +10 -10
  33. data/lib/protobuf/rpc/buffer.rb +7 -6
  34. data/lib/protobuf/rpc/client.rb +2 -30
  35. data/lib/protobuf/rpc/connectors/base.rb +168 -6
  36. data/lib/protobuf/rpc/connectors/ping.rb +2 -2
  37. data/lib/protobuf/rpc/connectors/socket.rb +6 -1
  38. data/lib/protobuf/rpc/connectors/zmq.rb +1 -2
  39. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -1
  40. data/lib/protobuf/rpc/error.rb +2 -2
  41. data/lib/protobuf/rpc/middleware/exception_handler.rb +4 -0
  42. data/lib/protobuf/rpc/middleware/logger.rb +4 -0
  43. data/lib/protobuf/rpc/middleware/request_decoder.rb +11 -16
  44. data/lib/protobuf/rpc/middleware/response_encoder.rb +18 -23
  45. data/lib/protobuf/rpc/rpc.pb.rb +2 -1
  46. data/lib/protobuf/rpc/rpc_method.rb +16 -0
  47. data/lib/protobuf/rpc/servers/socket/server.rb +4 -4
  48. data/lib/protobuf/rpc/servers/socket_runner.rb +8 -0
  49. data/lib/protobuf/rpc/servers/zmq/broker.rb +7 -6
  50. data/lib/protobuf/rpc/servers/zmq/server.rb +8 -7
  51. data/lib/protobuf/rpc/servers/zmq/util.rb +6 -6
  52. data/lib/protobuf/rpc/servers/zmq/worker.rb +7 -6
  53. data/lib/protobuf/rpc/servers/zmq_runner.rb +8 -0
  54. data/lib/protobuf/rpc/service.rb +6 -15
  55. data/lib/protobuf/rpc/service_directory.rb +1 -1
  56. data/lib/protobuf/rpc/service_dispatcher.rb +5 -6
  57. data/lib/protobuf/rpc/service_filters.rb +8 -30
  58. data/lib/protobuf/socket.rb +2 -2
  59. data/lib/protobuf/version.rb +1 -1
  60. data/lib/protobuf/zmq.rb +2 -2
  61. data/lib/protobuf.rb +12 -27
  62. data/protobuf.gemspec +5 -3
  63. data/spec/benchmark/tasks.rb +1 -0
  64. data/spec/functional/code_generator_spec.rb +38 -0
  65. data/spec/lib/protobuf/cli_spec.rb +19 -10
  66. data/spec/lib/protobuf/code_generator_spec.rb +28 -0
  67. data/spec/lib/protobuf/enum_spec.rb +6 -2
  68. data/spec/lib/protobuf/field/bool_field_spec.rb +4 -0
  69. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  70. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  71. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  72. data/spec/lib/protobuf/field/float_field_spec.rb +5 -1
  73. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  74. data/spec/lib/protobuf/field/message_field_spec.rb +53 -0
  75. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  76. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  77. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  78. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  79. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  80. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  81. data/spec/lib/protobuf/generators/base_spec.rb +69 -1
  82. data/spec/lib/protobuf/generators/enum_generator_spec.rb +1 -1
  83. data/spec/lib/protobuf/generators/field_generator_spec.rb +58 -0
  84. data/spec/lib/protobuf/generators/file_generator_spec.rb +47 -0
  85. data/spec/lib/protobuf/generators/service_generator_spec.rb +58 -14
  86. data/spec/lib/protobuf/message_spec.rb +2 -2
  87. data/spec/lib/protobuf/optionable_spec.rb +96 -0
  88. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +151 -0
  89. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +3 -3
  90. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +0 -2
  91. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +2 -2
  92. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +4 -4
  93. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +2 -2
  94. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +1 -18
  95. data/spec/lib/protobuf/rpc/service_filters_spec.rb +2 -2
  96. data/spec/lib/protobuf/varint_spec.rb +1 -1
  97. data/spec/lib/protobuf_spec.rb +13 -16
  98. data/spec/support/packed_field.rb +3 -2
  99. data/spec/support/protos/enum.pb.rb +2 -1
  100. data/spec/support/protos/enum.proto +1 -0
  101. data/spec/support/protos/google_unittest.pb.rb +69 -58
  102. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  103. data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
  104. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  105. data/spec/support/protos/google_unittest_import.pb.rb +8 -0
  106. data/spec/support/protos/google_unittest_import_public.pb.rb +6 -0
  107. data/spec/support/protos/resource.pb.rb +54 -2
  108. data/spec/support/protos/resource.proto +42 -2
  109. data/spec/support/server.rb +1 -1
  110. metadata +39 -16
  111. data/lib/protobuf/rpc/connector.rb +0 -19
  112. data/lib/protobuf/rpc/connectors/common.rb +0 -176
  113. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  114. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
@@ -8,6 +8,47 @@ RSpec.describe Protobuf::Rpc::Connectors::Base do
8
8
 
9
9
  subject { Protobuf::Rpc::Connectors::Base.new(options) }
10
10
 
11
+ context "API" do
12
+ specify { expect(subject.respond_to?(:any_callbacks?)).to be true }
13
+ specify { expect(subject.respond_to?(:request_caller)).to be true }
14
+ specify { expect(subject.respond_to?(:data_callback)).to be true }
15
+ specify { expect(subject.respond_to?(:error)).to be true }
16
+ specify { expect(subject.respond_to?(:failure)).to be true }
17
+ specify { expect(subject.respond_to?(:complete)).to be true }
18
+ specify { expect(subject.respond_to?(:parse_response)).to be true }
19
+ specify { expect(subject.respond_to?(:verify_options!)).to be true }
20
+ specify { expect(subject.respond_to?(:verify_callbacks)).to be true }
21
+ end
22
+
23
+ describe "#any_callbacks?" do
24
+ [:@complete_cb, :@success_cb, :@failure_cb].each do |cb|
25
+ it "returns true if #{cb} is provided" do
26
+ subject.instance_variable_set(cb, "something")
27
+ expect(subject.any_callbacks?).to be true
28
+ end
29
+ end
30
+
31
+ it "returns false when all callbacks are not provided" do
32
+ subject.instance_variable_set(:@complete_cb, nil)
33
+ subject.instance_variable_set(:@success_cb, nil)
34
+ subject.instance_variable_set(:@failure_cb, nil)
35
+
36
+ expect(subject.any_callbacks?).to be false
37
+ end
38
+ end
39
+
40
+ describe "#data_callback" do
41
+ it "changes state to use the data callback" do
42
+ subject.data_callback("data")
43
+ expect(subject.instance_variable_get(:@used_data_callback)).to be true
44
+ end
45
+
46
+ it "sets the data var when using the data_callback" do
47
+ subject.data_callback("data")
48
+ expect(subject.instance_variable_get(:@data)).to eq("data")
49
+ end
50
+ end
51
+
11
52
  describe "#send_request" do
12
53
  it "raising an error when 'send_request' is not overridden" do
13
54
  expect { subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/)
@@ -47,4 +88,114 @@ RSpec.describe Protobuf::Rpc::Connectors::Base do
47
88
  end
48
89
  end
49
90
 
91
+ describe '#request_bytes' do
92
+ let(:service) { Test::ResourceService }
93
+ let(:method) { :find }
94
+ let(:request) { '' }
95
+ let(:client_host) { 'myhost.myservice.com' }
96
+ let(:options) do
97
+ {
98
+ :service => service,
99
+ :method => method,
100
+ :request => request,
101
+ :client_host => client_host,
102
+ :timeout => 60,
103
+ }
104
+ end
105
+
106
+ let(:expected) do
107
+ ::Protobuf::Socketrpc::Request.new(
108
+ :service_name => service.name,
109
+ :method_name => 'find',
110
+ :request_proto => '',
111
+ :caller => client_host,
112
+ )
113
+ end
114
+
115
+ before { allow(subject).to receive(:validate_request_type!).and_return(true) }
116
+ before { expect(subject).not_to receive(:failure) }
117
+
118
+ specify { expect(subject.request_bytes).to eq expected.encode }
119
+ end
120
+
121
+ describe '#request_caller' do
122
+ specify { expect(subject.request_caller).to eq ::Protobuf.client_host }
123
+
124
+ context 'when "client_host" option is given to initializer' do
125
+ let(:hostname) { 'myhost.myserver.com' }
126
+ let(:options) { { :client_host => hostname, :timeout => 60 } }
127
+
128
+ specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host }
129
+ specify { expect(subject.request_caller).to eq hostname }
130
+ end
131
+ end
132
+
133
+ describe "#verify_callbacks" do
134
+ it "sets @failure_cb to #data_callback when no callbacks are defined" do
135
+ subject.verify_callbacks
136
+ expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback))
137
+ end
138
+
139
+ it "sets @success_cb to #data_callback when no callbacks are defined" do
140
+ subject.verify_callbacks
141
+ expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback))
142
+ end
143
+
144
+ it "doesn't set @failure_cb when already defined" do
145
+ set_cb = -> { true }
146
+ subject.instance_variable_set(:@failure_cb, set_cb)
147
+ subject.verify_callbacks
148
+ expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb)
149
+ expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback))
150
+ end
151
+
152
+ it "doesn't set @success_cb when already defined" do
153
+ set_cb = -> { true }
154
+ subject.instance_variable_set(:@success_cb, set_cb)
155
+ subject.verify_callbacks
156
+ expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb)
157
+ expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback))
158
+ end
159
+
160
+ end
161
+
162
+ shared_examples "a ConnectorDisposition" do |meth, cb, *args|
163
+
164
+ it "calls #complete before exit" do
165
+ subject.stats = double("Object", :stop => true)
166
+
167
+ expect(subject).to receive(:complete)
168
+ subject.method(meth).call(*args)
169
+ end
170
+
171
+ it "calls the #{cb} callback when provided" do
172
+ stats = double("Object")
173
+ allow(stats).to receive(:stop).and_return(true)
174
+ subject.stats = stats
175
+ some_cb = double("Object")
176
+
177
+ subject.instance_variable_set("@#{cb}", some_cb)
178
+ expect(some_cb).to receive(:call).and_return(true)
179
+ subject.method(meth).call(*args)
180
+ end
181
+
182
+ it "calls the complete callback when provided" do
183
+ stats = double("Object")
184
+ allow(stats).to receive(:stop).and_return(true)
185
+ subject.stats = stats
186
+ comp_cb = double("Object")
187
+
188
+ subject.instance_variable_set(:@complete_cb, comp_cb)
189
+ expect(comp_cb).to receive(:call).and_return(true)
190
+ subject.method(meth).call(*args)
191
+ end
192
+
193
+ end
194
+
195
+ it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message")
196
+ it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message")
197
+ it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response")
198
+ it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response")
199
+ it_behaves_like("a ConnectorDisposition", :complete, "complete_cb")
200
+
50
201
  end
@@ -55,14 +55,14 @@ require "protobuf/zmq"
55
55
 
56
56
  describe "#timeout" do
57
57
  it "uses the default value" do
58
- expect(subject.timeout).to eq(5)
58
+ expect(subject.timeout).to eq(0.2)
59
59
  end
60
60
 
61
61
  context "when environment variable is set" do
62
- before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "1" }
62
+ before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "100" }
63
63
 
64
64
  it "uses the environmet variable" do
65
- expect(subject.timeout).to eq(1)
65
+ expect(subject.timeout).to eq(0.1)
66
66
  end
67
67
  end
68
68
  end
@@ -18,8 +18,6 @@ RSpec.describe Protobuf::Rpc::Connectors::Socket do
18
18
 
19
19
  it_behaves_like "a Protobuf Connector"
20
20
 
21
- specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be true }
22
-
23
21
  context "#read_response" do
24
22
  let(:data) { "New data" }
25
23
 
@@ -21,13 +21,13 @@ RSpec.describe Protobuf::Rpc::Middleware::Logger do
21
21
  let(:request) { request_type.new(:name => 'required') }
22
22
  let(:request_type) { rpc_method.request_type }
23
23
  let(:request_wrapper) do
24
- Protobuf::Socketrpc::Request.new(
24
+ ::Protobuf::Socketrpc::Request.new(
25
25
  :service_name => service_name,
26
26
  :method_name => method_name.to_s,
27
27
  :request_proto => request,
28
28
  )
29
29
  end
30
- let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) }
30
+ let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) }
31
31
  let(:response) { rpc_method.response_type.new(:name => 'required') }
32
32
  let(:rpc_method) { service_class.rpcs[method_name] }
33
33
  let(:rpc_service) { service_class.new(env) }
@@ -14,7 +14,7 @@ RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do
14
14
  let(:request) { request_type.new(:name => 'required') }
15
15
  let(:request_type) { rpc_method.request_type }
16
16
  let(:request_wrapper) do
17
- Protobuf::Socketrpc::Request.new(
17
+ ::Protobuf::Socketrpc::Request.new(
18
18
  :caller => client_host,
19
19
  :service_name => service_name,
20
20
  :method_name => method_name.to_s,
@@ -75,7 +75,7 @@ RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do
75
75
  end
76
76
 
77
77
  context "when decoding fails" do
78
- before { allow(Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) }
78
+ before { allow(::Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) }
79
79
 
80
80
  it "raises a bad request data exception" do
81
81
  expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData)
@@ -84,7 +84,7 @@ RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do
84
84
 
85
85
  context "when the RPC service is not defined" do
86
86
  let(:request_wrapper) do
87
- Protobuf::Socketrpc::Request.new(
87
+ ::Protobuf::Socketrpc::Request.new(
88
88
  :caller => client_host,
89
89
  :service_name => 'Foo',
90
90
  :method_name => method_name.to_s,
@@ -99,7 +99,7 @@ RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do
99
99
 
100
100
  context "when RPC method is not defined" do
101
101
  let(:request_wrapper) do
102
- Protobuf::Socketrpc::Request.new(
102
+ ::Protobuf::Socketrpc::Request.new(
103
103
  :caller => client_host,
104
104
  :service_name => service_name,
105
105
  :method_name => 'foo',
@@ -10,7 +10,7 @@ RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do
10
10
  end
11
11
  let(:encoded_response) { response_wrapper.encode }
12
12
  let(:response) { Test::Resource.new(:name => 'required') }
13
- let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) }
13
+ let(:response_wrapper) { ::Protobuf::Socketrpc::Response.new(:response_proto => response) }
14
14
 
15
15
  subject { described_class.new(app) }
16
16
 
@@ -65,7 +65,7 @@ RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do
65
65
  end
66
66
 
67
67
  context "when encoding fails" do
68
- before { allow_any_instance_of(Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) }
68
+ before { allow_any_instance_of(::Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) }
69
69
 
70
70
  it "raises a bad request data exception" do
71
71
  expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError)
@@ -16,7 +16,6 @@ RSpec.describe Protobuf::Rpc::ServiceDispatcher do
16
16
  let(:request_type) { service_class.rpcs[method_name].request_type }
17
17
  let(:response) { response_type.new(:name => 'required') }
18
18
  let(:response_type) { service_class.rpcs[method_name].response_type }
19
-
20
19
  let(:rpc_service) { service_class.new(env) }
21
20
  let(:service_class) { Test::ResourceService }
22
21
  let(:service_name) { service_class.to_s }
@@ -29,24 +28,8 @@ RSpec.describe Protobuf::Rpc::ServiceDispatcher do
29
28
  before { allow(rpc_service).to receive(:response).and_return(response) }
30
29
 
31
30
  it "dispatches the request" do
32
- stack_env = subject.call(env)
31
+ stack_env = subject._call(env)
33
32
  expect(stack_env.response).to eq response
34
33
  end
35
-
36
- context "when the given RPC method is not implemented" do
37
- let(:method_name) { :find_not_implemented }
38
-
39
- it "raises a method not found exception" do
40
- expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound)
41
- end
42
- end
43
-
44
- context "when the given RPC method is implemented and a NoMethodError is raised" do
45
- before { allow(rpc_service).to receive(:callable_rpc_method).and_return(-> { rpc_service.__send__(:foo) }) }
46
-
47
- it "raises the exeception" do
48
- expect { subject.call(env) }.to raise_exception(NoMethodError)
49
- end
50
- end
51
34
  end
52
35
  end
@@ -362,7 +362,7 @@ RSpec.describe Protobuf::Rpc::ServiceFilters do
362
362
  :endpoint,
363
363
  :inner_around_bottom,
364
364
  :outer_around_bottom,
365
- ]
365
+ ],
366
366
  )
367
367
  end
368
368
 
@@ -390,7 +390,7 @@ RSpec.describe Protobuf::Rpc::ServiceFilters do
390
390
  :outer_around_top,
391
391
  :inner_around,
392
392
  :outer_around_bottom,
393
- ]
393
+ ],
394
394
  )
395
395
  end
396
396
 
@@ -11,7 +11,7 @@ RSpec.describe Protobuf::Varint do
11
11
  913_389 => "7d83",
12
12
  516_192_829_912_693 => "9eyMkpivdQ==",
13
13
  9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==",
14
- }
14
+ }.freeze
15
15
 
16
16
  [defined?(::Varint) ? ::Varint : nil, Protobuf::VarintPure].compact.each do |klass|
17
17
  context "with #{klass}" do
@@ -19,26 +19,23 @@ RSpec.describe ::Protobuf do
19
19
  end
20
20
  end
21
21
 
22
- describe '.connector_type' do
23
- before { described_class.instance_variable_set(:@connector_type, nil) }
24
-
25
- it 'defaults to socket' do
26
- expect(described_class.connector_type).to eq :socket
22
+ describe '.connector_type_class' do
23
+ it "defaults to Socket" do
24
+ described_class.connector_type_class = nil
25
+ expect(described_class.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Socket)
27
26
  end
28
27
 
29
- it 'accepts socket or zmq' do
30
- [:socket, :zmq].each do |type|
31
- described_class.connector_type = type
32
- expect(described_class.connector_type).to eq type
33
- end
28
+ it 'fails if fails to load the PB_CLIENT_TYPE' do
29
+ ENV['PB_CLIENT_TYPE'] = "something_to_autoload"
30
+ expect { load 'protobuf.rb' }.to raise_error(LoadError, /something_to_autoload/)
31
+ ENV.delete('PB_CLIENT_TYPE')
34
32
  end
35
33
 
36
- it 'does not accept other types' do
37
- [:hello, :world, :evented].each do |type|
38
- expect do
39
- described_class.connector_type = type
40
- end.to raise_error(ArgumentError)
41
- end
34
+ it 'loads the connector type class from PB_CLIENT_TYPE' do
35
+ ENV['PB_CLIENT_TYPE'] = "protobuf/rpc/connectors/zmq"
36
+ load 'protobuf.rb'
37
+ expect(::Protobuf.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Zmq)
38
+ ENV.delete('PB_CLIENT_TYPE')
42
39
  end
43
40
  end
44
41
 
@@ -12,11 +12,12 @@ if defined?(RSpec)
12
12
  end
13
13
 
14
14
  let(:field_name) { "#{field_klass.name.split('::').last.underscore}_packed_field".to_sym }
15
- let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) }
15
+ let(:value) { [100, 200, 300] }
16
+ let(:message_instance) { PackableFieldTest.new(field_name => value) }
16
17
 
17
18
  subject { PackableFieldTest.get_field(field_name) }
18
19
 
19
20
  specify { expect(subject).to be_packed }
20
-
21
+ specify { expect(PackableFieldTest.decode(message_instance.encode).send(field_name)).to eq value }
21
22
  end
22
23
  end
@@ -18,12 +18,13 @@ module Test
18
18
  # Enum Classes
19
19
  #
20
20
  class EnumTestType < ::Protobuf::Enum
21
+ define :ZERO, 0
21
22
  define :ONE, 1
22
23
  define :TWO, 2
23
24
  end
24
25
 
25
26
  class AliasedEnum < ::Protobuf::Enum
26
- set_option :allow_alias
27
+ set_option :allow_alias, true
27
28
 
28
29
  define :THREE, 3
29
30
  define :TRES, 3
@@ -6,6 +6,7 @@ import 'protos/resource.proto';
6
6
  // Test extending another message from an imported file.
7
7
 
8
8
  enum EnumTestType {
9
+ ZERO = 0;
9
10
  ONE = 1;
10
11
  TWO = 2;
11
12
  }
@@ -25,7 +25,7 @@ module Protobuf_unittest
25
25
  end
26
26
 
27
27
  class TestEnumWithDupValue < ::Protobuf::Enum
28
- set_option :allow_alias
28
+ set_option :allow_alias, true
29
29
 
30
30
  define :FOO1, 1
31
31
  define :BAR1, 2
@@ -175,6 +175,17 @@ module Protobuf_unittest
175
175
  class BarResponse < ::Protobuf::Message; end
176
176
 
177
177
 
178
+ ##
179
+ # File Options
180
+ #
181
+ set_option :java_outer_classname, "UnittestProto"
182
+ set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
183
+ set_option :cc_generic_services, true
184
+ set_option :java_generic_services, true
185
+ set_option :py_generic_services, true
186
+ set_option :cc_enable_arenas, true
187
+
188
+
178
189
  ##
179
190
  # Message Fields
180
191
  #
@@ -213,10 +224,10 @@ module Protobuf_unittest
213
224
  optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21
214
225
  optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum, 22
215
226
  optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum, 23
216
- optional :string, :optional_string_piece, 24
217
- optional :string, :optional_cord, 25
227
+ optional :string, :optional_string_piece, 24, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
228
+ optional :string, :optional_cord, 25, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
218
229
  optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message, 26
219
- optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27
230
+ optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27, :lazy => true
220
231
  repeated :int32, :repeated_int32, 31
221
232
  repeated :int64, :repeated_int64, 32
222
233
  repeated :uint32, :repeated_uint32, 33
@@ -239,9 +250,9 @@ module Protobuf_unittest
239
250
  repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51
240
251
  repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum, 52
241
252
  repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum, 53
242
- repeated :string, :repeated_string_piece, 54
243
- repeated :string, :repeated_cord, 55
244
- repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57
253
+ repeated :string, :repeated_string_piece, 54, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
254
+ repeated :string, :repeated_cord, 55, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
255
+ repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57, :lazy => true
245
256
  optional :int32, :default_int32, 61, :default => 41
246
257
  optional :int64, :default_int64, 62, :default => 42
247
258
  optional :uint32, :default_uint32, 63, :default => 43
@@ -260,8 +271,8 @@ module Protobuf_unittest
260
271
  optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR
261
272
  optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR
262
273
  optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR
263
- optional :string, :default_string_piece, 84, :default => "abc"
264
- optional :string, :default_cord, 85, :default => "123"
274
+ optional :string, :default_string_piece, 84, :default => "abc", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
275
+ optional :string, :default_cord, 85, :default => "123", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
265
276
  optional :uint32, :oneof_uint32, 111
266
277
  optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message, 112
267
278
  optional :string, :oneof_string, 113
@@ -307,10 +318,10 @@ module Protobuf_unittest
307
318
  optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.optional_nested_enum_extension", 21, :extension => true
308
319
  optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.optional_foreign_enum_extension", 22, :extension => true
309
320
  optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.optional_import_enum_extension", 23, :extension => true
310
- optional :string, :".protobuf_unittest.optional_string_piece_extension", 24, :extension => true
311
- optional :string, :".protobuf_unittest.optional_cord_extension", 25, :extension => true
321
+ optional :string, :".protobuf_unittest.optional_string_piece_extension", 24, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
322
+ optional :string, :".protobuf_unittest.optional_cord_extension", 25, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
312
323
  optional ::Protobuf_unittest_import::PublicImportMessage, :".protobuf_unittest.optional_public_import_message_extension", 26, :extension => true
313
- optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_lazy_message_extension", 27, :extension => true
324
+ optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.optional_lazy_message_extension", 27, :extension => true, :lazy => true
314
325
  repeated :int32, :".protobuf_unittest.repeated_int32_extension", 31, :extension => true
315
326
  repeated :int64, :".protobuf_unittest.repeated_int64_extension", 32, :extension => true
316
327
  repeated :uint32, :".protobuf_unittest.repeated_uint32_extension", 33, :extension => true
@@ -333,9 +344,9 @@ module Protobuf_unittest
333
344
  repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.repeated_nested_enum_extension", 51, :extension => true
334
345
  repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.repeated_foreign_enum_extension", 52, :extension => true
335
346
  repeated ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.repeated_import_enum_extension", 53, :extension => true
336
- repeated :string, :".protobuf_unittest.repeated_string_piece_extension", 54, :extension => true
337
- repeated :string, :".protobuf_unittest.repeated_cord_extension", 55, :extension => true
338
- repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_lazy_message_extension", 57, :extension => true
347
+ repeated :string, :".protobuf_unittest.repeated_string_piece_extension", 54, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
348
+ repeated :string, :".protobuf_unittest.repeated_cord_extension", 55, :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
349
+ repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.repeated_lazy_message_extension", 57, :extension => true, :lazy => true
339
350
  optional :int32, :".protobuf_unittest.default_int32_extension", 61, :default => 41, :extension => true
340
351
  optional :int64, :".protobuf_unittest.default_int64_extension", 62, :default => 42, :extension => true
341
352
  optional :uint32, :".protobuf_unittest.default_uint32_extension", 63, :default => 43, :extension => true
@@ -354,8 +365,8 @@ module Protobuf_unittest
354
365
  optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :".protobuf_unittest.default_nested_enum_extension", 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true
355
366
  optional ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.default_foreign_enum_extension", 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true
356
367
  optional ::Protobuf_unittest_import::ImportEnum, :".protobuf_unittest.default_import_enum_extension", 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true
357
- optional :string, :".protobuf_unittest.default_string_piece_extension", 84, :default => "abc", :extension => true
358
- optional :string, :".protobuf_unittest.default_cord_extension", 85, :default => "123", :extension => true
368
+ optional :string, :".protobuf_unittest.default_string_piece_extension", 84, :default => "abc", :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
369
+ optional :string, :".protobuf_unittest.default_cord_extension", 85, :default => "123", :extension => true, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
359
370
  optional :uint32, :".protobuf_unittest.oneof_uint32_extension", 111, :extension => true
360
371
  optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :".protobuf_unittest.oneof_nested_message_extension", 112, :extension => true
361
372
  optional :string, :".protobuf_unittest.oneof_string_extension", 113, :extension => true
@@ -455,11 +466,11 @@ module Protobuf_unittest
455
466
  end
456
467
 
457
468
  class TestEagerMessage
458
- optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1
469
+ optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1, :lazy => false
459
470
  end
460
471
 
461
472
  class TestLazyMessage
462
- optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1
473
+ optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1, :lazy => true
463
474
  end
464
475
 
465
476
  class TestNestedMessageHasBits
@@ -476,14 +487,14 @@ module Protobuf_unittest
476
487
  optional :string, :StringField, 2
477
488
  optional ::Protobuf_unittest::ForeignEnum, :EnumField, 3
478
489
  optional ::Protobuf_unittest::ForeignMessage, :MessageField, 4
479
- optional :string, :StringPieceField, 5
480
- optional :string, :CordField, 6
490
+ optional :string, :StringPieceField, 5, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
491
+ optional :string, :CordField, 6, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
481
492
  repeated :int32, :RepeatedPrimitiveField, 7
482
493
  repeated :string, :RepeatedStringField, 8
483
494
  repeated ::Protobuf_unittest::ForeignEnum, :RepeatedEnumField, 9
484
495
  repeated ::Protobuf_unittest::ForeignMessage, :RepeatedMessageField, 10
485
- repeated :string, :RepeatedStringPieceField, 11
486
- repeated :string, :RepeatedCordField, 12
496
+ repeated :string, :RepeatedStringPieceField, 11, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
497
+ repeated :string, :RepeatedCordField, 12, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
487
498
  end
488
499
 
489
500
  class TestFieldOrderings
@@ -528,8 +539,8 @@ module Protobuf_unittest
528
539
  optional :string, :cpp_trigraph, 20, :default => "? ? ?? ?? ??? ??/ ??-"
529
540
  optional :string, :string_with_zero, 23, :default => "hello"
530
541
  optional :bytes, :bytes_with_zero, 24, :default => "wor\000ld"
531
- optional :string, :string_piece_with_zero, 25, :default => "abc"
532
- optional :string, :cord_with_zero, 26, :default => "123"
542
+ optional :string, :string_piece_with_zero, 25, :default => "abc", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
543
+ optional :string, :cord_with_zero, 26, :default => "123", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
533
544
  optional :string, :replacement_string, 27, :default => "${unknown}"
534
545
  end
535
546
 
@@ -610,17 +621,17 @@ module Protobuf_unittest
610
621
 
611
622
  optional :int32, :foo_int, 1
612
623
  optional :string, :foo_string, 2
613
- optional :string, :foo_cord, 3
614
- optional :string, :foo_string_piece, 4
624
+ optional :string, :foo_cord, 3, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
625
+ optional :string, :foo_string_piece, 4, :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
615
626
  optional :bytes, :foo_bytes, 5
616
627
  optional ::Protobuf_unittest::TestOneof2::NestedEnum, :foo_enum, 6
617
628
  optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_message, 7
618
629
  optional ::Protobuf_unittest::TestOneof2::FooGroup, :foogroup, 8
619
- optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11
630
+ optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11, :lazy => true
620
631
  optional :int32, :bar_int, 12, :default => 5
621
632
  optional :string, :bar_string, 13, :default => "STRING"
622
- optional :string, :bar_cord, 14, :default => "CORD"
623
- optional :string, :bar_string_piece, 15, :default => "SPIECE"
633
+ optional :string, :bar_cord, 14, :default => "CORD", :ctype => ::Google::Protobuf::FieldOptions::CType::CORD
634
+ optional :string, :bar_string_piece, 15, :default => "SPIECE", :ctype => ::Google::Protobuf::FieldOptions::CType::STRING_PIECE
624
635
  optional :bytes, :bar_bytes, 16, :default => "BYTES"
625
636
  optional ::Protobuf_unittest::TestOneof2::NestedEnum, :bar_enum, 17, :default => ::Protobuf_unittest::TestOneof2::NestedEnum::BAR
626
637
  optional :int32, :baz_int, 18
@@ -655,20 +666,20 @@ module Protobuf_unittest
655
666
  end
656
667
 
657
668
  class TestUnpackedTypes
658
- repeated :int32, :unpacked_int32, 90
659
- repeated :int64, :unpacked_int64, 91
660
- repeated :uint32, :unpacked_uint32, 92
661
- repeated :uint64, :unpacked_uint64, 93
662
- repeated :sint32, :unpacked_sint32, 94
663
- repeated :sint64, :unpacked_sint64, 95
664
- repeated :fixed32, :unpacked_fixed32, 96
665
- repeated :fixed64, :unpacked_fixed64, 97
666
- repeated :sfixed32, :unpacked_sfixed32, 98
667
- repeated :sfixed64, :unpacked_sfixed64, 99
668
- repeated :float, :unpacked_float, 100
669
- repeated :double, :unpacked_double, 101
670
- repeated :bool, :unpacked_bool, 102
671
- repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103
669
+ repeated :int32, :unpacked_int32, 90, :packed => false
670
+ repeated :int64, :unpacked_int64, 91, :packed => false
671
+ repeated :uint32, :unpacked_uint32, 92, :packed => false
672
+ repeated :uint64, :unpacked_uint64, 93, :packed => false
673
+ repeated :sint32, :unpacked_sint32, 94, :packed => false
674
+ repeated :sint64, :unpacked_sint64, 95, :packed => false
675
+ repeated :fixed32, :unpacked_fixed32, 96, :packed => false
676
+ repeated :fixed64, :unpacked_fixed64, 97, :packed => false
677
+ repeated :sfixed32, :unpacked_sfixed32, 98, :packed => false
678
+ repeated :sfixed64, :unpacked_sfixed64, 99, :packed => false
679
+ repeated :float, :unpacked_float, 100, :packed => false
680
+ repeated :double, :unpacked_double, 101, :packed => false
681
+ repeated :bool, :unpacked_bool, 102, :packed => false
682
+ repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103, :packed => false
672
683
  end
673
684
 
674
685
  class TestPackedExtensions
@@ -693,20 +704,20 @@ module Protobuf_unittest
693
704
  class TestUnpackedExtensions
694
705
  # Extension Fields
695
706
  extensions 1...536870912
696
- repeated :int32, :".protobuf_unittest.unpacked_int32_extension", 90, :extension => true
697
- repeated :int64, :".protobuf_unittest.unpacked_int64_extension", 91, :extension => true
698
- repeated :uint32, :".protobuf_unittest.unpacked_uint32_extension", 92, :extension => true
699
- repeated :uint64, :".protobuf_unittest.unpacked_uint64_extension", 93, :extension => true
700
- repeated :sint32, :".protobuf_unittest.unpacked_sint32_extension", 94, :extension => true
701
- repeated :sint64, :".protobuf_unittest.unpacked_sint64_extension", 95, :extension => true
702
- repeated :fixed32, :".protobuf_unittest.unpacked_fixed32_extension", 96, :extension => true
703
- repeated :fixed64, :".protobuf_unittest.unpacked_fixed64_extension", 97, :extension => true
704
- repeated :sfixed32, :".protobuf_unittest.unpacked_sfixed32_extension", 98, :extension => true
705
- repeated :sfixed64, :".protobuf_unittest.unpacked_sfixed64_extension", 99, :extension => true
706
- repeated :float, :".protobuf_unittest.unpacked_float_extension", 100, :extension => true
707
- repeated :double, :".protobuf_unittest.unpacked_double_extension", 101, :extension => true
708
- repeated :bool, :".protobuf_unittest.unpacked_bool_extension", 102, :extension => true
709
- repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.unpacked_enum_extension", 103, :extension => true
707
+ repeated :int32, :".protobuf_unittest.unpacked_int32_extension", 90, :extension => true, :packed => false
708
+ repeated :int64, :".protobuf_unittest.unpacked_int64_extension", 91, :extension => true, :packed => false
709
+ repeated :uint32, :".protobuf_unittest.unpacked_uint32_extension", 92, :extension => true, :packed => false
710
+ repeated :uint64, :".protobuf_unittest.unpacked_uint64_extension", 93, :extension => true, :packed => false
711
+ repeated :sint32, :".protobuf_unittest.unpacked_sint32_extension", 94, :extension => true, :packed => false
712
+ repeated :sint64, :".protobuf_unittest.unpacked_sint64_extension", 95, :extension => true, :packed => false
713
+ repeated :fixed32, :".protobuf_unittest.unpacked_fixed32_extension", 96, :extension => true, :packed => false
714
+ repeated :fixed64, :".protobuf_unittest.unpacked_fixed64_extension", 97, :extension => true, :packed => false
715
+ repeated :sfixed32, :".protobuf_unittest.unpacked_sfixed32_extension", 98, :extension => true, :packed => false
716
+ repeated :sfixed64, :".protobuf_unittest.unpacked_sfixed64_extension", 99, :extension => true, :packed => false
717
+ repeated :float, :".protobuf_unittest.unpacked_float_extension", 100, :extension => true, :packed => false
718
+ repeated :double, :".protobuf_unittest.unpacked_double_extension", 101, :extension => true, :packed => false
719
+ repeated :bool, :".protobuf_unittest.unpacked_bool_extension", 102, :extension => true, :packed => false
720
+ repeated ::Protobuf_unittest::ForeignEnum, :".protobuf_unittest.unpacked_enum_extension", 103, :extension => true, :packed => false
710
721
  end
711
722
 
712
723
  class TestDynamicExtensions