upfluence-thrift 2.1.1 → 2.2.0
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.
- checksums.yaml +4 -4
- data/lib/thrift/client.rb +30 -9
- data/lib/thrift/definition.rb +45 -5
- data/lib/thrift/middleware.rb +13 -0
- data/lib/thrift/processor.rb +2 -9
- data/lib/thrift/struct.rb +10 -10
- data/lib/thrift/transport/server_socket.rb +6 -6
- metadata +2 -74
- data/benchmark/gen-rb/benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/benchmark_service.rb +0 -91
- data/benchmark/gen-rb/benchmark_types.rb +0 -10
- data/spec/gen-rb/base/base_service.rb +0 -91
- data/spec/gen-rb/base/base_service_constants.rb +0 -11
- data/spec/gen-rb/base/base_service_types.rb +0 -26
- data/spec/gen-rb/extended/extended_service.rb +0 -89
- data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
- data/spec/gen-rb/extended/extended_service_types.rb +0 -12
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -299
- data/spec/gen-rb/flat/referenced_constants.rb +0 -11
- data/spec/gen-rb/flat/referenced_types.rb +0 -17
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -299
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/nonblocking_service.rb +0 -299
- data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
- data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
- data/spec/gen-rb/thrift_spec_constants.rb +0 -11
- data/spec/gen-rb/thrift_spec_types.rb +0 -538
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -274
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -761
- data/test/debug_proto/gen-rb/empty_service.rb +0 -31
- data/test/debug_proto/gen-rb/inherited.rb +0 -90
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -93
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -92
- data/test/debug_proto/gen-rb/srv.rb +0 -361
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb0c6edc7181a95e78d4f3d1da97bf55cff534a6c4f3784c998bbefa1fc0df1c
|
4
|
+
data.tar.gz: c225382fb7a4bc1a0c4896f74a970c669eaf7cac96414b6c7e1be3d1dc7e66e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bfbd290bda69a9ca7102791fd2291e35902691598be71d1a1429dd16329ef9dad76a38d363e76098ee2b88af7ce8df93927b0f0458f41b93b8e4ec133b227b7
|
7
|
+
data.tar.gz: ffbb8d16a28268f9cb6cc82fa089e9bb06f96aefb3097077923478e4547fbc5cec43b2b640e0a790434e5ed41422236405c75bb835c5e2ac7735352e0dae182b
|
data/lib/thrift/client.rb
CHANGED
@@ -20,17 +20,9 @@
|
|
20
20
|
|
21
21
|
module Thrift
|
22
22
|
module Client
|
23
|
-
def initialize(iprot,
|
23
|
+
def initialize(iprot, oprot = nil)
|
24
24
|
@iprot = iprot
|
25
25
|
@oprot = oprot || iprot
|
26
|
-
@middleware = case middlewares.length
|
27
|
-
when 0
|
28
|
-
Middleware::NOP_MIDDLEWARE
|
29
|
-
when 1
|
30
|
-
middlewares.first
|
31
|
-
else
|
32
|
-
Middleware::MultiMiddleware.new(middlewares)
|
33
|
-
end
|
34
26
|
@seqid = 0
|
35
27
|
end
|
36
28
|
|
@@ -48,9 +40,15 @@ module Thrift
|
|
48
40
|
|
49
41
|
def send_message_args(args_class, args)
|
50
42
|
data = args_class.new
|
43
|
+
|
51
44
|
args.each do |k, v|
|
52
45
|
data.send("#{k.to_s}=", v)
|
53
46
|
end
|
47
|
+
|
48
|
+
send_message_instance(data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def send_message_instance(data)
|
54
52
|
begin
|
55
53
|
data.write(@oprot)
|
56
54
|
rescue StandardError => e
|
@@ -95,4 +93,27 @@ module Thrift
|
|
95
93
|
raise x
|
96
94
|
end
|
97
95
|
end
|
96
|
+
|
97
|
+
class BaseClient
|
98
|
+
include Client
|
99
|
+
|
100
|
+
def call_unary(name, req)
|
101
|
+
@oprot.write_message_begin(name, Thrift::MessageTypes::ONEWAY, @seqid)
|
102
|
+
send_message_instance(req)
|
103
|
+
end
|
104
|
+
|
105
|
+
def call_binary(name, req, resp_klass)
|
106
|
+
@oprot.write_message_begin(name, Thrift::MessageTypes::CALL, @seqid)
|
107
|
+
send_message_instance(req)
|
108
|
+
receive_message(resp_klass)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class << self
|
113
|
+
def build_client(input)
|
114
|
+
return BaseClient.new(input) if input.is_a? BaseProtocol
|
115
|
+
|
116
|
+
input
|
117
|
+
end
|
118
|
+
end
|
98
119
|
end
|
data/lib/thrift/definition.rb
CHANGED
@@ -1,24 +1,64 @@
|
|
1
1
|
module Thrift
|
2
2
|
class StructDefinition
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :klass
|
4
|
+
|
4
5
|
def initialize(klass)
|
5
|
-
@namespace = klass::NAMESPACE
|
6
|
-
@name = klass::NAME
|
7
6
|
@klass = klass
|
8
7
|
end
|
9
8
|
|
9
|
+
def namespace
|
10
|
+
@klass::NAMESPACE
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@klass::NAME
|
15
|
+
end
|
16
|
+
|
10
17
|
def struct_type
|
11
|
-
"#{
|
18
|
+
"#{namespace}.#{name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ServiceDefinition < StructDefinition
|
23
|
+
attr_reader :klass
|
24
|
+
|
25
|
+
def initialize(klass)
|
26
|
+
@klass = klass
|
27
|
+
end
|
28
|
+
|
29
|
+
def client_class
|
30
|
+
@klass::Client
|
31
|
+
end
|
32
|
+
|
33
|
+
def processor_class
|
34
|
+
@klass::Processor
|
35
|
+
end
|
36
|
+
|
37
|
+
def namespace
|
38
|
+
@klass::NAMESPACE
|
39
|
+
end
|
40
|
+
|
41
|
+
def service
|
42
|
+
@klass::SERVICE
|
43
|
+
end
|
44
|
+
|
45
|
+
def service_type
|
46
|
+
"#{namespace}.#{service}"
|
12
47
|
end
|
13
48
|
end
|
14
49
|
|
15
50
|
STRUCT_DEFINITIONS = {}
|
51
|
+
SERVICE_DEFINITIONS = {}
|
16
52
|
|
17
53
|
class << self
|
18
|
-
|
19
54
|
def register_struct_type(klass)
|
20
55
|
definition = StructDefinition.new(klass)
|
21
56
|
STRUCT_DEFINITIONS[definition.struct_type] = definition
|
22
57
|
end
|
58
|
+
|
59
|
+
def register_service_type(klass)
|
60
|
+
definition = ServiceDefinition.new(klass)
|
61
|
+
SERVICE_DEFINITIONS[definition.service_type] = definition
|
62
|
+
end
|
23
63
|
end
|
24
64
|
end
|
data/lib/thrift/middleware.rb
CHANGED
@@ -33,5 +33,18 @@ module Thrift
|
|
33
33
|
end
|
34
34
|
|
35
35
|
NOP_MIDDLEWARE = NopMiddleware.new
|
36
|
+
|
37
|
+
class << self
|
38
|
+
def wrap(middlewares)
|
39
|
+
case middlewares.length
|
40
|
+
when 0
|
41
|
+
NOP_MIDDLEWARE
|
42
|
+
when 1
|
43
|
+
middlewares.first
|
44
|
+
else
|
45
|
+
MultiMiddleware.new(middlewares)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
data/lib/thrift/processor.rb
CHANGED
@@ -21,14 +21,7 @@ module Thrift
|
|
21
21
|
module Processor
|
22
22
|
def initialize(handler, middlewares = [])
|
23
23
|
@handler = handler
|
24
|
-
@middleware =
|
25
|
-
when 0
|
26
|
-
Middleware::NOP_MIDDLEWARE
|
27
|
-
when 1
|
28
|
-
middlewares.first
|
29
|
-
else
|
30
|
-
Middleware::MultiMiddleware.new(middlewares)
|
31
|
-
end
|
24
|
+
@middleware = Middleware.wrap(middlewares)
|
32
25
|
end
|
33
26
|
|
34
27
|
def process(iprot, oprot)
|
@@ -46,7 +39,7 @@ module Thrift
|
|
46
39
|
write_exception(
|
47
40
|
ApplicationException.new(
|
48
41
|
ApplicationException::UNKNOWN_METHOD,
|
49
|
-
'Unknown function '+name,
|
42
|
+
'Unknown function ' + name,
|
50
43
|
),
|
51
44
|
oprot,
|
52
45
|
name,
|
data/lib/thrift/struct.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
#
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -6,16 +6,16 @@
|
|
6
6
|
# to you under the Apache License, Version 2.0 (the
|
7
7
|
# "License"); you may not use this file except in compliance
|
8
8
|
# with the License. You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing,
|
13
13
|
# software distributed under the License is distributed on an
|
14
14
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
#
|
18
|
+
#
|
19
19
|
|
20
20
|
require 'set'
|
21
21
|
|
@@ -24,15 +24,15 @@ module Thrift
|
|
24
24
|
def initialize(d={}, &block)
|
25
25
|
# get a copy of the default values to work on, removing defaults in favor of arguments
|
26
26
|
fields_with_defaults = fields_with_default_values.dup
|
27
|
-
|
28
|
-
# check if the defaults is empty, or if there are no parameters for this
|
27
|
+
|
28
|
+
# check if the defaults is empty, or if there are no parameters for this
|
29
29
|
# instantiation, and if so, don't bother overriding defaults.
|
30
30
|
unless fields_with_defaults.empty? || d.empty?
|
31
31
|
d.each_key do |name|
|
32
32
|
fields_with_defaults.delete(name.to_s)
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# assign all the user-specified arguments
|
37
37
|
unless d.empty?
|
38
38
|
d.each do |name, value|
|
@@ -43,14 +43,14 @@ module Thrift
|
|
43
43
|
instance_variable_set("@#{name}", value)
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
# assign all the default values
|
48
48
|
unless fields_with_defaults.empty?
|
49
49
|
fields_with_defaults.each do |name, default_value|
|
50
50
|
instance_variable_set("@#{name}", (default_value.dup rescue default_value))
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
yield self if block_given?
|
55
55
|
end
|
56
56
|
|
@@ -67,7 +67,7 @@ module Thrift
|
|
67
67
|
end
|
68
68
|
fields_with_default_values
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def inspect(skip_optional_nulls = true)
|
72
72
|
fields = []
|
73
73
|
each_field do |fid, field_info|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: ascii-8bit
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
4
4
|
# or more contributor license agreements. See the NOTICE file
|
5
5
|
# distributed with this work for additional information
|
@@ -7,16 +7,16 @@
|
|
7
7
|
# to you under the Apache License, Version 2.0 (the
|
8
8
|
# "License"); you may not use this file except in compliance
|
9
9
|
# with the License. You may obtain a copy of the License at
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Unless required by applicable law or agreed to in writing,
|
14
14
|
# software distributed under the License is distributed on an
|
15
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
16
|
# KIND, either express or implied. See the License for the
|
17
17
|
# specific language governing permissions and limitations
|
18
18
|
# under the License.
|
19
|
-
#
|
19
|
+
#
|
20
20
|
|
21
21
|
require 'socket'
|
22
22
|
|
@@ -37,7 +37,7 @@ module Thrift
|
|
37
37
|
attr_reader :handle
|
38
38
|
|
39
39
|
def listen
|
40
|
-
@handle
|
40
|
+
@handle ||= TCPServer.new(@host, @port)
|
41
41
|
end
|
42
42
|
|
43
43
|
def accept
|
@@ -60,4 +60,4 @@ module Thrift
|
|
60
60
|
|
61
61
|
alias to_io handle
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upfluence-thrift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thrift Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: statsd-ruby
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
description: Ruby bindings for the Apache Thrift RPC system
|
112
98
|
email:
|
113
99
|
- dev@thrift.apache.org
|
@@ -183,9 +169,6 @@ files:
|
|
183
169
|
- benchmark/Benchmark.thrift
|
184
170
|
- benchmark/benchmark.rb
|
185
171
|
- benchmark/client.rb
|
186
|
-
- benchmark/gen-rb/benchmark_constants.rb
|
187
|
-
- benchmark/gen-rb/benchmark_service.rb
|
188
|
-
- benchmark/gen-rb/benchmark_types.rb
|
189
172
|
- benchmark/server.rb
|
190
173
|
- benchmark/thin_server.rb
|
191
174
|
- ext/binary_protocol_accelerated.c
|
@@ -265,25 +248,6 @@ files:
|
|
265
248
|
- spec/compact_protocol_spec.rb
|
266
249
|
- spec/exception_spec.rb
|
267
250
|
- spec/flat_spec.rb
|
268
|
-
- spec/gen-rb/base/base_service.rb
|
269
|
-
- spec/gen-rb/base/base_service_constants.rb
|
270
|
-
- spec/gen-rb/base/base_service_types.rb
|
271
|
-
- spec/gen-rb/extended/extended_service.rb
|
272
|
-
- spec/gen-rb/extended/extended_service_constants.rb
|
273
|
-
- spec/gen-rb/extended/extended_service_types.rb
|
274
|
-
- spec/gen-rb/flat/namespaced_nonblocking_service.rb
|
275
|
-
- spec/gen-rb/flat/referenced_constants.rb
|
276
|
-
- spec/gen-rb/flat/referenced_types.rb
|
277
|
-
- spec/gen-rb/flat/thrift_namespaced_spec_constants.rb
|
278
|
-
- spec/gen-rb/flat/thrift_namespaced_spec_types.rb
|
279
|
-
- spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb
|
280
|
-
- spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb
|
281
|
-
- spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb
|
282
|
-
- spec/gen-rb/nonblocking_service.rb
|
283
|
-
- spec/gen-rb/other_namespace/referenced_constants.rb
|
284
|
-
- spec/gen-rb/other_namespace/referenced_types.rb
|
285
|
-
- spec/gen-rb/thrift_spec_constants.rb
|
286
|
-
- spec/gen-rb/thrift_spec_types.rb
|
287
251
|
- spec/http_client_spec.rb
|
288
252
|
- spec/json_protocol_spec.rb
|
289
253
|
- spec/namespaced_spec.rb
|
@@ -302,13 +266,6 @@ files:
|
|
302
266
|
- spec/types_spec.rb
|
303
267
|
- spec/union_spec.rb
|
304
268
|
- spec/unix_socket_spec.rb
|
305
|
-
- test/debug_proto/gen-rb/debug_proto_test_constants.rb
|
306
|
-
- test/debug_proto/gen-rb/debug_proto_test_types.rb
|
307
|
-
- test/debug_proto/gen-rb/empty_service.rb
|
308
|
-
- test/debug_proto/gen-rb/inherited.rb
|
309
|
-
- test/debug_proto/gen-rb/reverse_order_service.rb
|
310
|
-
- test/debug_proto/gen-rb/service_for_exception_with_a_map.rb
|
311
|
-
- test/debug_proto/gen-rb/srv.rb
|
312
269
|
homepage: http://thrift.apache.org
|
313
270
|
licenses:
|
314
271
|
- Apache 2.0
|
@@ -340,13 +297,6 @@ signing_key:
|
|
340
297
|
specification_version: 4
|
341
298
|
summary: Ruby bindings for Apache Thrift
|
342
299
|
test_files:
|
343
|
-
- test/debug_proto/gen-rb/debug_proto_test_constants.rb
|
344
|
-
- test/debug_proto/gen-rb/debug_proto_test_types.rb
|
345
|
-
- test/debug_proto/gen-rb/service_for_exception_with_a_map.rb
|
346
|
-
- test/debug_proto/gen-rb/inherited.rb
|
347
|
-
- test/debug_proto/gen-rb/reverse_order_service.rb
|
348
|
-
- test/debug_proto/gen-rb/empty_service.rb
|
349
|
-
- test/debug_proto/gen-rb/srv.rb
|
350
300
|
- spec/ThriftSpec.thrift
|
351
301
|
- spec/struct_nested_containers_spec.rb
|
352
302
|
- spec/http_client_spec.rb
|
@@ -368,25 +318,6 @@ test_files:
|
|
368
318
|
- spec/unix_socket_spec.rb
|
369
319
|
- spec/ExtendedService.thrift
|
370
320
|
- spec/types_spec.rb
|
371
|
-
- spec/gen-rb/flat/thrift_namespaced_spec_constants.rb
|
372
|
-
- spec/gen-rb/flat/namespaced_nonblocking_service.rb
|
373
|
-
- spec/gen-rb/flat/referenced_constants.rb
|
374
|
-
- spec/gen-rb/flat/referenced_types.rb
|
375
|
-
- spec/gen-rb/flat/thrift_namespaced_spec_types.rb
|
376
|
-
- spec/gen-rb/other_namespace/referenced_constants.rb
|
377
|
-
- spec/gen-rb/other_namespace/referenced_types.rb
|
378
|
-
- spec/gen-rb/extended/extended_service.rb
|
379
|
-
- spec/gen-rb/extended/extended_service_types.rb
|
380
|
-
- spec/gen-rb/extended/extended_service_constants.rb
|
381
|
-
- spec/gen-rb/thrift_spec_constants.rb
|
382
|
-
- spec/gen-rb/nonblocking_service.rb
|
383
|
-
- spec/gen-rb/thrift_spec_types.rb
|
384
|
-
- spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb
|
385
|
-
- spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb
|
386
|
-
- spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb
|
387
|
-
- spec/gen-rb/base/base_service.rb
|
388
|
-
- spec/gen-rb/base/base_service_constants.rb
|
389
|
-
- spec/gen-rb/base/base_service_types.rb
|
390
321
|
- spec/exception_spec.rb
|
391
322
|
- spec/ThriftNamespacedSpec.thrift
|
392
323
|
- spec/struct_spec.rb
|
@@ -400,9 +331,6 @@ test_files:
|
|
400
331
|
- spec/base_transport_spec.rb
|
401
332
|
- spec/nonblocking_server_spec.rb
|
402
333
|
- benchmark/Benchmark.thrift
|
403
|
-
- benchmark/gen-rb/benchmark_service.rb
|
404
|
-
- benchmark/gen-rb/benchmark_constants.rb
|
405
|
-
- benchmark/gen-rb/benchmark_types.rb
|
406
334
|
- benchmark/client.rb
|
407
335
|
- benchmark/benchmark.rb
|
408
336
|
- benchmark/thin_server.rb
|
@@ -1,91 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Autogenerated by Thrift Compiler (2.0.1-upfluence)
|
3
|
-
#
|
4
|
-
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
-
#
|
6
|
-
|
7
|
-
require 'thrift'
|
8
|
-
require 'benchmark_types'
|
9
|
-
|
10
|
-
module ThriftBenchmark
|
11
|
-
module BenchmarkService
|
12
|
-
SERVICE_NAME = "BenchmarkService"
|
13
|
-
PROGRAM_NAME = ""
|
14
|
-
|
15
|
-
class Client
|
16
|
-
include ::Thrift::Client
|
17
|
-
|
18
|
-
def self.from_provider(provider)
|
19
|
-
Client.new(*provider.build(", BenchmarkService"))
|
20
|
-
end
|
21
|
-
|
22
|
-
def fibonacci(ctx, n)
|
23
|
-
@middleware.handle_binary(ctx, 'fibonacci', Fibonacci_args.new(:n => n)) do |ctx, args|
|
24
|
-
send_fibonacci(ctx, args.n)
|
25
|
-
return recv_fibonacci(ctx)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def send_fibonacci(ctx, n)
|
30
|
-
send_message('fibonacci', Fibonacci_args, :n => n)
|
31
|
-
end
|
32
|
-
|
33
|
-
def recv_fibonacci(ctx)
|
34
|
-
result = receive_message(Fibonacci_result)
|
35
|
-
return result.success unless result.success.nil?
|
36
|
-
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'fibonacci failed: unknown result')
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
class Processor
|
42
|
-
include ::Thrift::Processor
|
43
|
-
|
44
|
-
def process_fibonacci(ctx, seqid, iprot, oprot)
|
45
|
-
args = read_args(iprot, Fibonacci_args)
|
46
|
-
@middleware.handle_binary(ctx, 'fibonacci', args) do |ctx, args|
|
47
|
-
result = Fibonacci_result.new()
|
48
|
-
result.success = @handler.fibonacci(ctx, args.n)
|
49
|
-
write_result(result, oprot, 'fibonacci', seqid)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
# HELPER FUNCTIONS AND STRUCTURES
|
56
|
-
|
57
|
-
class Fibonacci_args
|
58
|
-
include ::Thrift::Struct, ::Thrift::Struct_Union
|
59
|
-
N = 1
|
60
|
-
|
61
|
-
FIELDS = {
|
62
|
-
N => {:type => ::Thrift::Types::BYTE, :name => 'n'}
|
63
|
-
}
|
64
|
-
|
65
|
-
def struct_fields; FIELDS; end
|
66
|
-
|
67
|
-
def validate
|
68
|
-
end
|
69
|
-
|
70
|
-
::Thrift::Struct.generate_accessors self
|
71
|
-
end
|
72
|
-
|
73
|
-
class Fibonacci_result
|
74
|
-
include ::Thrift::Struct, ::Thrift::Struct_Union
|
75
|
-
SUCCESS = 0
|
76
|
-
|
77
|
-
FIELDS = {
|
78
|
-
SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success'}
|
79
|
-
}
|
80
|
-
|
81
|
-
def struct_fields; FIELDS; end
|
82
|
-
|
83
|
-
def validate
|
84
|
-
end
|
85
|
-
|
86
|
-
::Thrift::Struct.generate_accessors self
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|