thrift 0.22.0 → 0.23.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/README.md +175 -17
- data/benchmark/benchmark.rb +22 -8
- data/benchmark/client.rb +49 -6
- data/benchmark/server.rb +45 -7
- data/benchmark/thin_server.rb +1 -0
- data/ext/binary_protocol_accelerated.c +76 -19
- data/ext/compact_protocol.c +80 -15
- data/ext/constants.h +12 -0
- data/ext/extconf.rb +10 -9
- data/ext/memory_buffer.c +7 -7
- data/ext/protocol.c +29 -0
- data/ext/protocol.h +35 -0
- data/ext/struct.c +36 -5
- data/ext/thrift_native.c +27 -3
- data/lib/thrift/bytes.rb +68 -101
- data/lib/thrift/client.rb +61 -9
- data/lib/thrift/exceptions.rb +5 -5
- data/lib/thrift/multiplexed_processor.rb +6 -6
- data/lib/thrift/processor.rb +6 -6
- data/lib/thrift/protocol/base_protocol.rb +37 -15
- data/lib/thrift/protocol/binary_protocol.rb +25 -9
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +5 -5
- data/lib/thrift/protocol/compact_protocol.rb +61 -37
- data/lib/thrift/protocol/header_protocol.rb +320 -0
- data/lib/thrift/protocol/json_protocol.rb +26 -16
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -5
- data/lib/thrift/protocol/protocol_decorator.rb +12 -4
- data/lib/thrift/serializer/deserializer.rb +5 -5
- data/lib/thrift/serializer/serializer.rb +4 -5
- data/lib/thrift/server/base_server.rb +4 -4
- data/lib/thrift/server/mongrel_http_server.rb +6 -6
- data/lib/thrift/server/nonblocking_server.rb +8 -8
- data/lib/thrift/server/simple_server.rb +4 -4
- data/lib/thrift/server/thin_http_server.rb +3 -3
- data/lib/thrift/server/thread_pool_server.rb +6 -6
- data/lib/thrift/server/threaded_server.rb +4 -4
- data/lib/thrift/struct.rb +11 -11
- data/lib/thrift/struct_union.rb +19 -9
- data/lib/thrift/thrift_native.rb +1 -1
- data/lib/thrift/transport/base_server_transport.rb +5 -5
- data/lib/thrift/transport/base_transport.rb +12 -12
- data/lib/thrift/transport/buffered_transport.rb +6 -6
- data/lib/thrift/transport/framed_transport.rb +7 -7
- data/lib/thrift/transport/header_transport.rb +516 -0
- data/lib/thrift/transport/http_client_transport.rb +1 -1
- data/lib/thrift/transport/io_stream_transport.rb +3 -3
- data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
- data/lib/thrift/transport/server_socket.rb +8 -5
- data/lib/thrift/transport/socket.rb +58 -31
- data/lib/thrift/transport/ssl_server_socket.rb +1 -1
- data/lib/thrift/transport/ssl_socket.rb +2 -2
- data/lib/thrift/transport/unix_server_socket.rb +4 -4
- data/lib/thrift/transport/unix_socket.rb +6 -6
- data/lib/thrift/types.rb +9 -6
- data/lib/thrift/union.rb +14 -8
- data/lib/thrift/uuid.rb +49 -0
- data/lib/thrift.rb +3 -1
- data/spec/ThriftSpec.thrift +5 -1
- data/spec/base_protocol_spec.rb +1 -2
- data/spec/base_transport_spec.rb +6 -7
- data/spec/binary_protocol_spec.rb +0 -2
- data/spec/binary_protocol_spec_shared.rb +129 -142
- data/spec/bytes_spec.rb +57 -118
- data/spec/client_spec.rb +85 -19
- data/spec/compact_protocol_spec.rb +54 -16
- data/spec/constants_demo_spec.rb +101 -0
- data/spec/exception_spec.rb +0 -1
- data/spec/header_protocol_spec.rb +475 -0
- data/spec/header_transport_spec.rb +386 -0
- data/spec/http_client_spec.rb +4 -6
- data/spec/json_protocol_spec.rb +47 -47
- data/spec/namespaced_spec.rb +0 -1
- data/spec/nonblocking_server_spec.rb +102 -4
- data/spec/processor_spec.rb +0 -1
- data/spec/serializer_spec.rb +0 -1
- data/spec/server_socket_spec.rb +1 -1
- data/spec/server_spec.rb +8 -9
- data/spec/socket_spec.rb +0 -1
- data/spec/socket_spec_shared.rb +72 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/ssl_server_socket_spec.rb +12 -1
- data/spec/ssl_socket_spec.rb +10 -1
- data/spec/struct_nested_containers_spec.rb +1 -2
- data/spec/struct_spec.rb +113 -9
- data/spec/support/header_protocol_helper.rb +54 -0
- data/spec/thin_http_server_spec.rb +3 -18
- data/spec/types_spec.rb +25 -26
- data/spec/union_spec.rb +69 -11
- data/spec/unix_socket_spec.rb +1 -2
- data/spec/uuid_validation_spec.rb +238 -0
- data/test/fuzz/Makefile.am +173 -0
- data/test/fuzz/README.md +149 -0
- data/test/fuzz/fuzz_common.rb +95 -0
- data/{lib/thrift/core_ext.rb → test/fuzz/fuzz_parse_binary_protocol.rb} +3 -4
- data/{lib/thrift/core_ext/fixnum.rb → test/fuzz/fuzz_parse_binary_protocol_accelerated.rb} +6 -13
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +22 -0
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_parse_compact_protocol.rb +22 -0
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_parse_json_protocol.rb +22 -0
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +22 -0
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +22 -0
- data/test/fuzz/fuzz_tracer.rb +28 -0
- metadata +106 -37
|
@@ -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,9 +6,9 @@
|
|
|
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
|
|
@@ -39,7 +39,7 @@ module Thrift
|
|
|
39
39
|
@server_transport.close
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
def to_s
|
|
44
44
|
"simple(#{super.to_s})"
|
|
45
45
|
end
|
|
@@ -32,7 +32,7 @@ module Thrift
|
|
|
32
32
|
# * :ip
|
|
33
33
|
# * :path
|
|
34
34
|
# * :protocol_factory
|
|
35
|
-
def initialize(processor, options={})
|
|
35
|
+
def initialize(processor, options = {})
|
|
36
36
|
port = options[:port] || 80
|
|
37
37
|
ip = options[:ip] || "0.0.0.0"
|
|
38
38
|
path = options[:path] || "/"
|
|
@@ -60,9 +60,9 @@ module Thrift
|
|
|
60
60
|
run lambda { |env|
|
|
61
61
|
request = Rack::Request.new(env)
|
|
62
62
|
if RackApplication.valid_thrift_request?(request)
|
|
63
|
-
RackApplication.successful_request(request, processor, protocol_factory)
|
|
63
|
+
RackApplication.successful_request(request, processor, protocol_factory).finish
|
|
64
64
|
else
|
|
65
|
-
RackApplication.failed_request
|
|
65
|
+
RackApplication.failed_request.finish
|
|
66
66
|
end
|
|
67
67
|
}
|
|
68
68
|
end
|
|
@@ -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,22 +6,22 @@
|
|
|
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 'thread'
|
|
21
21
|
|
|
22
22
|
module Thrift
|
|
23
23
|
class ThreadPoolServer < BaseServer
|
|
24
|
-
def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil, num=20)
|
|
24
|
+
def initialize(processor, server_transport, transport_factory = nil, protocol_factory = nil, num = 20)
|
|
25
25
|
super(processor, server_transport, transport_factory, protocol_factory)
|
|
26
26
|
@thread_q = SizedQueue.new(num)
|
|
27
27
|
@exception_q = Queue.new
|
|
@@ -71,7 +71,7 @@ module Thrift
|
|
|
71
71
|
@server_transport.close
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
def to_s
|
|
76
76
|
"threadpool(#{super.to_s})"
|
|
77
77
|
end
|
|
@@ -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,9 +6,9 @@
|
|
|
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
|
|
@@ -43,7 +43,7 @@ module Thrift
|
|
|
43
43
|
@server_transport.close
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
def to_s
|
|
48
48
|
"threaded(#{super.to_s})"
|
|
49
49
|
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,33 +6,33 @@
|
|
|
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
|
|
|
22
22
|
module Thrift
|
|
23
23
|
module Struct
|
|
24
|
-
def initialize(d={}, &block)
|
|
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|
|
data/lib/thrift/struct_union.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,9 +6,9 @@
|
|
|
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
|
|
@@ -20,6 +20,12 @@ require 'set'
|
|
|
20
20
|
|
|
21
21
|
module Thrift
|
|
22
22
|
module Struct_Union
|
|
23
|
+
def validate_container_size(size)
|
|
24
|
+
return size unless size < 0
|
|
25
|
+
|
|
26
|
+
raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, 'Negative size')
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
def name_to_id(name)
|
|
24
30
|
names_to_ids = self.class.instance_variable_get(:@names_to_ids)
|
|
25
31
|
unless names_to_ids
|
|
@@ -55,6 +61,7 @@ module Thrift
|
|
|
55
61
|
value.read(iprot)
|
|
56
62
|
when Types::MAP
|
|
57
63
|
key_type, val_type, size = iprot.read_map_begin
|
|
64
|
+
validate_container_size(size)
|
|
58
65
|
# Skip the map contents if the declared key or value types don't match the expected ones.
|
|
59
66
|
if (size != 0 && (key_type != field[:key][:type] || val_type != field[:value][:type]))
|
|
60
67
|
size.times do
|
|
@@ -73,6 +80,7 @@ module Thrift
|
|
|
73
80
|
iprot.read_map_end
|
|
74
81
|
when Types::LIST
|
|
75
82
|
e_type, size = iprot.read_list_begin
|
|
83
|
+
validate_container_size(size)
|
|
76
84
|
# Skip the list contents if the declared element type doesn't match the expected one.
|
|
77
85
|
if (e_type != field[:element][:type])
|
|
78
86
|
size.times do
|
|
@@ -80,13 +88,15 @@ module Thrift
|
|
|
80
88
|
end
|
|
81
89
|
value = nil
|
|
82
90
|
else
|
|
83
|
-
value =
|
|
84
|
-
|
|
91
|
+
value = []
|
|
92
|
+
size.times do
|
|
93
|
+
value << read_field(iprot, field_info(field[:element]))
|
|
85
94
|
end
|
|
86
95
|
end
|
|
87
96
|
iprot.read_list_end
|
|
88
97
|
when Types::SET
|
|
89
98
|
e_type, size = iprot.read_set_begin
|
|
99
|
+
validate_container_size(size)
|
|
90
100
|
# Skip the set contents if the declared element type doesn't match the expected one.
|
|
91
101
|
if (e_type != field[:element][:type])
|
|
92
102
|
size.times do
|
|
@@ -159,7 +169,7 @@ module Thrift
|
|
|
159
169
|
def inspect_field(value, field_info)
|
|
160
170
|
if enum_class = field_info[:enum_class]
|
|
161
171
|
"#{enum_class.const_get(:VALUE_MAP)[value]} (#{value})"
|
|
162
|
-
elsif value.is_a? Hash
|
|
172
|
+
elsif value.is_a? Hash
|
|
163
173
|
if field_info[:type] == Types::MAP
|
|
164
174
|
map_buf = []
|
|
165
175
|
value.each do |k, v|
|
|
@@ -180,13 +190,13 @@ module Thrift
|
|
|
180
190
|
value.inspect
|
|
181
191
|
end
|
|
182
192
|
end
|
|
183
|
-
|
|
193
|
+
|
|
184
194
|
def inspect_collection(collection, field_info)
|
|
185
195
|
buf = []
|
|
186
196
|
collection.each do |k|
|
|
187
197
|
buf << inspect_field(k, field_info[:element])
|
|
188
198
|
end
|
|
189
|
-
"[" + buf.join(", ") + "]"
|
|
199
|
+
"[" + buf.join(", ") + "]"
|
|
190
200
|
end
|
|
191
201
|
end
|
|
192
|
-
end
|
|
202
|
+
end
|
data/lib/thrift/thrift_native.rb
CHANGED
|
@@ -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
|
module Thrift
|
|
22
22
|
class BaseServerTransport
|
|
@@ -27,7 +27,7 @@ module Thrift
|
|
|
27
27
|
def accept
|
|
28
28
|
raise NotImplementedError
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def close; nil; end
|
|
32
32
|
|
|
33
33
|
def closed?
|
|
@@ -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
|
module Thrift
|
|
22
22
|
class TransportException < Exception
|
|
@@ -28,7 +28,7 @@ module Thrift
|
|
|
28
28
|
|
|
29
29
|
attr_reader :type
|
|
30
30
|
|
|
31
|
-
def initialize(type=UNKNOWN, message=nil)
|
|
31
|
+
def initialize(type = UNKNOWN, message = nil)
|
|
32
32
|
super(message)
|
|
33
33
|
@type = type
|
|
34
34
|
end
|
|
@@ -48,12 +48,12 @@ module Thrift
|
|
|
48
48
|
|
|
49
49
|
class BaseTransport
|
|
50
50
|
def open?; end
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
def open; end
|
|
53
53
|
|
|
54
54
|
def close; end
|
|
55
55
|
|
|
56
|
-
# Reads a number of bytes from the transports.
|
|
56
|
+
# Reads a number of bytes from the transports. The String returned will have a BINARY (aka ASCII-8BIT) encoding.
|
|
57
57
|
#
|
|
58
58
|
# sz - The number of bytes to read from the transport.
|
|
59
59
|
#
|
|
@@ -62,7 +62,7 @@ module Thrift
|
|
|
62
62
|
raise NotImplementedError
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
# Returns an unsigned byte as a
|
|
65
|
+
# Returns an unsigned byte as a Integer in the range (0..255).
|
|
66
66
|
def read_byte
|
|
67
67
|
buf = read_all(1)
|
|
68
68
|
return Bytes.get_string_byte(buf, 0)
|
|
@@ -86,11 +86,11 @@ module Thrift
|
|
|
86
86
|
chunk = read(size - buf.length)
|
|
87
87
|
buf << chunk
|
|
88
88
|
end
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
buf
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
# Writes the byte buffer to the transport.
|
|
93
|
+
# Writes the byte buffer to the transport. The buffer will be forced into BINARY encoding.
|
|
94
94
|
#
|
|
95
95
|
# buf - A String acting as a byte buffer.
|
|
96
96
|
#
|
|
@@ -104,12 +104,12 @@ module Thrift
|
|
|
104
104
|
"base"
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
class BaseTransportFactory
|
|
109
109
|
def get_transport(trans)
|
|
110
110
|
return trans
|
|
111
111
|
end
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
def to_s
|
|
114
114
|
"base"
|
|
115
115
|
end
|
|
@@ -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,9 +7,9 @@
|
|
|
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
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
module Thrift
|
|
22
22
|
class BufferedTransport < BaseTransport
|
|
23
23
|
DEFAULT_BUFFER = 4096
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def initialize(transport)
|
|
26
26
|
@transport = transport
|
|
27
27
|
@wbuf = Bytes.empty_byte_buffer
|
|
@@ -101,7 +101,7 @@ module Thrift
|
|
|
101
101
|
@transport.write(@wbuf)
|
|
102
102
|
@wbuf = Bytes.empty_byte_buffer
|
|
103
103
|
end
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
@transport.flush
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -114,7 +114,7 @@ module Thrift
|
|
|
114
114
|
def get_transport(transport)
|
|
115
115
|
return BufferedTransport.new(transport)
|
|
116
116
|
end
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
def to_s
|
|
119
119
|
"buffered"
|
|
120
120
|
end
|
|
@@ -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,9 +7,9 @@
|
|
|
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
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
|
|
21
21
|
module Thrift
|
|
22
22
|
class FramedTransport < BaseTransport
|
|
23
|
-
def initialize(transport, read=true, write=true)
|
|
23
|
+
def initialize(transport, read = true, write = true)
|
|
24
24
|
@transport = transport
|
|
25
25
|
@rbuf = Bytes.empty_byte_buffer
|
|
26
26
|
@wbuf = Bytes.empty_byte_buffer
|
|
27
27
|
@read = read
|
|
28
28
|
@write = write
|
|
29
|
-
@index
|
|
29
|
+
@index = 0
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def open?
|
|
@@ -77,7 +77,7 @@ module Thrift
|
|
|
77
77
|
i
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def write(buf, sz=nil)
|
|
80
|
+
def write(buf, sz = nil)
|
|
81
81
|
return @transport.write(buf) unless @write
|
|
82
82
|
|
|
83
83
|
buf = Bytes.force_binary_encoding(buf)
|
|
@@ -117,7 +117,7 @@ module Thrift
|
|
|
117
117
|
def get_transport(transport)
|
|
118
118
|
return FramedTransport.new(transport)
|
|
119
119
|
end
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
def to_s
|
|
122
122
|
"framed"
|
|
123
123
|
end
|