upfluence-thrift 1.0.11 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/thrift.rb +6 -4
- data/lib/thrift/client.rb +31 -1
- data/lib/thrift/definition.rb +64 -0
- data/lib/thrift/exceptions.rb +5 -5
- data/lib/thrift/middleware.rb +50 -0
- data/lib/thrift/processor.rb +3 -3
- data/lib/thrift/protocol/json_protocol.rb +6 -6
- data/lib/thrift/server/rack_application.rb +30 -19
- data/lib/thrift/struct.rb +10 -10
- data/lib/thrift/transport/base_transport.rb +9 -7
- data/lib/thrift/transport/server_socket.rb +6 -6
- data/lib/thrift/types.rb +4 -4
- data/lib/thrift/types/known/any.rb +179 -0
- data/lib/thrift/types/known/any_constants.rb +17 -0
- data/lib/thrift/types/known/any_types.rb +43 -0
- data/lib/thrift/types/known/duration.rb +27 -0
- data/lib/thrift/types/known/duration_constants.rb +17 -0
- data/lib/thrift/types/known/duration_types.rb +43 -0
- data/lib/thrift/types/known/timestamp.rb +31 -0
- data/lib/thrift/types/known/timestamp_constants.rb +17 -0
- data/lib/thrift/types/known/timestamp_types.rb +43 -0
- data/lib/thrift/types/value.rb +114 -0
- data/lib/thrift/types/value_constants.rb +15 -0
- data/lib/thrift/types/value_types.rb +213 -0
- data/spec/binary_protocol_spec_shared.rb +57 -60
- data/spec/client_spec.rb +2 -2
- data/spec/compact_protocol_spec.rb +26 -20
- data/spec/http_client_spec.rb +7 -20
- data/spec/nonblocking_server_spec.rb +1 -1
- data/spec/processor_spec.rb +1 -1
- data/spec/rack_application_spec.rb +1 -1
- data/spec/struct_spec.rb +2 -2
- data/spec/types/known/any_spec.rb +44 -0
- data/spec/types/known/duration_spec.rb +20 -0
- data/spec/types/known/timestamp_spec.rb +17 -0
- data/spec/types/value_spec.rb +43 -0
- data/spec/types_spec.rb +2 -2
- metadata +50 -87
- data/benchmark/gen-rb/benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -10
- data/spec/gen-rb/base/base_service.rb +0 -80
- 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 -78
- 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 -272
- 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 -272
- 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 -272
- 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 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea7054176b376c94f565f2a9404599502b35853c1fcba1735d7153a16ccb1fa7
|
4
|
+
data.tar.gz: d90c18cf190256af2d4a0240bb4867bcf7b6e53b2f29f021e90e9d8eb8976a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c69f0f716a5f5be7d9ee0a8e06c5d66463dc5ba5a7714c3f6e8db51248933d06d78c0b32b7217112358a0dcfc9e973195efd412e6b2cac526134074af228d7
|
7
|
+
data.tar.gz: 0c6b50c4e0b91776991f82f4b80d053685a1f9c09e16ef5bb1efea0dbec866ebde4dc1c2a0dac26cd1c05d9f1d7c7afb3131078d47f2380e963767c4c4c7e78e
|
data/lib/thrift.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,28 +6,30 @@
|
|
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
|
# Contains some contributions under the Thrift Software License.
|
20
20
|
# Please see doc/old-thrift-license.txt in the Thrift distribution for
|
21
21
|
# details.
|
22
22
|
|
23
23
|
$:.unshift File.dirname(__FILE__)
|
24
24
|
|
25
|
+
require 'thrift/definition'
|
25
26
|
require 'thrift/bytes'
|
26
27
|
require 'thrift/core_ext'
|
27
28
|
require 'thrift/exceptions'
|
28
29
|
require 'thrift/types'
|
29
30
|
require 'thrift/processor'
|
30
31
|
require 'thrift/multiplexed_processor'
|
32
|
+
require 'thrift/middleware'
|
31
33
|
require 'thrift/client'
|
32
34
|
require 'thrift/struct'
|
33
35
|
require 'thrift/union'
|
data/lib/thrift/client.rb
CHANGED
@@ -16,10 +16,11 @@
|
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
18
|
#
|
19
|
+
#
|
19
20
|
|
20
21
|
module Thrift
|
21
22
|
module Client
|
22
|
-
def initialize(iprot, oprot=nil)
|
23
|
+
def initialize(iprot, oprot = nil)
|
23
24
|
@iprot = iprot
|
24
25
|
@oprot = oprot || iprot
|
25
26
|
@seqid = 0
|
@@ -39,9 +40,15 @@ module Thrift
|
|
39
40
|
|
40
41
|
def send_message_args(args_class, args)
|
41
42
|
data = args_class.new
|
43
|
+
|
42
44
|
args.each do |k, v|
|
43
45
|
data.send("#{k.to_s}=", v)
|
44
46
|
end
|
47
|
+
|
48
|
+
send_message_instance(data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def send_message_instance(data)
|
45
52
|
begin
|
46
53
|
data.write(@oprot)
|
47
54
|
rescue StandardError => e
|
@@ -86,4 +93,27 @@ module Thrift
|
|
86
93
|
raise x
|
87
94
|
end
|
88
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
|
89
119
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Thrift
|
2
|
+
class StructDefinition
|
3
|
+
attr_reader :klass
|
4
|
+
|
5
|
+
def initialize(klass)
|
6
|
+
@klass = klass
|
7
|
+
end
|
8
|
+
|
9
|
+
def namespace
|
10
|
+
@klass::NAMESPACE
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@klass::NAME
|
15
|
+
end
|
16
|
+
|
17
|
+
def struct_type
|
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}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
STRUCT_DEFINITIONS = {}
|
51
|
+
SERVICE_DEFINITIONS = {}
|
52
|
+
|
53
|
+
class << self
|
54
|
+
def register_struct_type(klass)
|
55
|
+
definition = StructDefinition.new(klass)
|
56
|
+
STRUCT_DEFINITIONS[definition.struct_type] = definition
|
57
|
+
end
|
58
|
+
|
59
|
+
def register_service_type(klass)
|
60
|
+
definition = ServiceDefinition.new(klass)
|
61
|
+
SERVICE_DEFINITIONS[definition.service_type] = definition
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/thrift/exceptions.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,21 +6,21 @@
|
|
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
|
module Thrift
|
21
21
|
class Exception < StandardError
|
22
22
|
def initialize(message)
|
23
|
-
super
|
23
|
+
super(message)
|
24
24
|
@message = message
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Thrift
|
2
|
+
module Middleware
|
3
|
+
class NopMiddleware
|
4
|
+
def handle_binary(_mth, args = {}, &block)
|
5
|
+
block.call(args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def handle_unary(_mth, args = {}, &block)
|
9
|
+
block.call(args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MultiMiddleware
|
14
|
+
def initialize(middlewares)
|
15
|
+
@middlewares = middlewares
|
16
|
+
end
|
17
|
+
|
18
|
+
def handle_unary(mth, args = {}, &block)
|
19
|
+
@middlewares.reverse.reduce(block) do |acc, m|
|
20
|
+
Proc.new do |args|
|
21
|
+
m.handle_unary(mth, args) { |args| acc.call(args) }
|
22
|
+
end
|
23
|
+
end.call(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_binary(mth, args = {}, &block)
|
27
|
+
@middlewares.reverse.reduce(block) do |acc, m|
|
28
|
+
Proc.new do |args|
|
29
|
+
m.handle_binary(mth, args) { |args| acc.call(args) }
|
30
|
+
end
|
31
|
+
end.call(args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
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
|
49
|
+
end
|
50
|
+
end
|
data/lib/thrift/processor.rb
CHANGED
@@ -19,8 +19,9 @@
|
|
19
19
|
|
20
20
|
module Thrift
|
21
21
|
module Processor
|
22
|
-
def initialize(handler)
|
22
|
+
def initialize(handler, middlewares = [])
|
23
23
|
@handler = handler
|
24
|
+
@middleware = Middleware.wrap(middlewares)
|
24
25
|
end
|
25
26
|
|
26
27
|
def process(iprot, oprot)
|
@@ -31,7 +32,6 @@ module Thrift
|
|
31
32
|
rescue => e
|
32
33
|
write_exception(e, oprot, name, seqid)
|
33
34
|
end
|
34
|
-
|
35
35
|
true
|
36
36
|
else
|
37
37
|
iprot.skip(Types::STRUCT)
|
@@ -39,7 +39,7 @@ module Thrift
|
|
39
39
|
write_exception(
|
40
40
|
ApplicationException.new(
|
41
41
|
ApplicationException::UNKNOWN_METHOD,
|
42
|
-
'Unknown function '+name,
|
42
|
+
'Unknown function ' + name,
|
43
43
|
),
|
44
44
|
oprot,
|
45
45
|
name,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
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
|
|
22
22
|
module Thrift
|
@@ -469,7 +469,7 @@ module Thrift
|
|
469
469
|
end
|
470
470
|
|
471
471
|
def write_string(str)
|
472
|
-
write_json_string(str)
|
472
|
+
write_json_string(Bytes.convert_to_utf8_byte_buffer(str))
|
473
473
|
end
|
474
474
|
|
475
475
|
def write_binary(str)
|
@@ -753,7 +753,7 @@ module Thrift
|
|
753
753
|
end
|
754
754
|
|
755
755
|
def read_string
|
756
|
-
read_json_string
|
756
|
+
Bytes.convert_to_string(read_json_string)
|
757
757
|
end
|
758
758
|
|
759
759
|
def read_binary
|
@@ -21,37 +21,48 @@ require 'rack'
|
|
21
21
|
|
22
22
|
module Thrift
|
23
23
|
class RackApplication
|
24
|
-
THRIFT_HEADER =
|
24
|
+
THRIFT_HEADER = 'application/x-thrift'.freeze
|
25
25
|
|
26
26
|
def self.for(path, processor, protocol_factory)
|
27
27
|
Rack::Builder.new do
|
28
28
|
map path do
|
29
|
-
run
|
30
|
-
request = Rack::Request.new(env)
|
31
|
-
if RackApplication.valid_thrift_request?(request)
|
32
|
-
RackApplication.successful_request(request, processor, protocol_factory)
|
33
|
-
else
|
34
|
-
RackApplication.failed_request
|
35
|
-
end
|
36
|
-
}
|
29
|
+
run Thrift::RackApplication.new(processor, protocol_factory)
|
37
30
|
end
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
processor.process protocol, protocol
|
46
|
-
response
|
34
|
+
def initialize(processor, protocol_factory)
|
35
|
+
@processor = processor
|
36
|
+
@protocol_factory = protocol_factory
|
37
|
+
@headers = { 'Content-Type' => THRIFT_HEADER }
|
47
38
|
end
|
48
39
|
|
49
|
-
def
|
50
|
-
Rack::
|
40
|
+
def call(env)
|
41
|
+
req = Rack::Request.new(env)
|
42
|
+
|
43
|
+
if valid_thrift_request?(req)
|
44
|
+
successful_request(req)
|
45
|
+
else
|
46
|
+
failed_request
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def successful_request(req)
|
51
|
+
resp = Rack::Response.new([], 200, @headers)
|
52
|
+
transport = IOStreamTransport.new req.body, resp
|
53
|
+
protocol = @protocol_factory.get_protocol transport
|
54
|
+
|
55
|
+
@processor.process protocol, protocol
|
56
|
+
|
57
|
+
[resp.status, resp.headers, resp.body]
|
58
|
+
end
|
59
|
+
|
60
|
+
def failed_request
|
61
|
+
[404, @headers, 'Not found']
|
51
62
|
end
|
52
63
|
|
53
|
-
def
|
54
|
-
|
64
|
+
def valid_thrift_request?(req)
|
65
|
+
req.post? && req.env['CONTENT_TYPE'] == THRIFT_HEADER
|
55
66
|
end
|
56
67
|
end
|
57
68
|
end
|
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|
|