thrift 0.23.0 → 0.25.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 +203 -40
- data/ext/binary_protocol_accelerated.c +130 -40
- data/ext/bytes.c +14 -0
- data/ext/compact_protocol.c +184 -91
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +12 -4
- data/ext/macros.h +11 -0
- data/ext/memory_buffer.c +67 -12
- data/ext/struct.c +192 -71
- data/ext/thrift_native.c +7 -0
- data/lib/thrift/bytes.rb +6 -3
- data/lib/thrift/client.rb +31 -33
- data/lib/thrift/exceptions.rb +11 -8
- data/lib/thrift/multiplexed_processor.rb +17 -8
- data/lib/thrift/processor.rb +25 -3
- data/lib/thrift/protocol/base_protocol.rb +66 -31
- data/lib/thrift/protocol/binary_protocol.rb +80 -37
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
- data/lib/thrift/protocol/compact_protocol.rb +204 -88
- data/lib/thrift/protocol/header_protocol.rb +15 -3
- data/lib/thrift/protocol/json_protocol.rb +158 -109
- data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
- data/lib/thrift/protocol/protocol_decorator.rb +6 -2
- data/lib/thrift/serializer/deserializer.rb +1 -0
- data/lib/thrift/serializer/serializer.rb +7 -0
- data/lib/thrift/server/base_server.rb +11 -2
- data/lib/thrift/server/nonblocking_server.rb +69 -20
- data/lib/thrift/server/rack_application.rb +69 -0
- data/lib/thrift/server/simple_server.rb +27 -15
- data/lib/thrift/server/thin_http_server.rb +21 -44
- data/lib/thrift/server/thread_pool_server.rb +21 -17
- data/lib/thrift/server/threaded_server.rb +22 -18
- data/lib/thrift/struct.rb +34 -18
- data/lib/thrift/struct_union.rb +37 -36
- data/lib/thrift/thrift_native.rb +2 -1
- data/lib/thrift/transport/base_server_transport.rb +3 -0
- data/lib/thrift/transport/base_transport.rb +26 -4
- data/lib/thrift/transport/buffered_transport.rb +5 -4
- data/lib/thrift/transport/framed_transport.rb +33 -7
- data/lib/thrift/transport/header_transport.rb +159 -33
- data/lib/thrift/transport/http_client_transport.rb +28 -14
- data/lib/thrift/transport/io_stream_transport.rb +3 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
- data/lib/thrift/transport/server_socket.rb +10 -8
- data/lib/thrift/transport/socket.rb +85 -48
- data/lib/thrift/transport/ssl_server_socket.rb +67 -6
- data/lib/thrift/transport/ssl_socket.rb +73 -14
- data/lib/thrift/transport/unix_server_socket.rb +6 -2
- data/lib/thrift/transport/unix_socket.rb +5 -6
- data/lib/thrift/types.rb +23 -22
- data/lib/thrift/union.rb +21 -11
- data/lib/thrift/uuid.rb +9 -8
- data/lib/thrift.rb +40 -39
- metadata +7 -266
- data/benchmark/Benchmark.thrift +0 -24
- data/benchmark/benchmark.rb +0 -285
- data/benchmark/client.rb +0 -117
- data/benchmark/server.rb +0 -120
- data/benchmark/thin_server.rb +0 -45
- data/lib/thrift/server/mongrel_http_server.rb +0 -60
- data/spec/BaseService.thrift +0 -27
- data/spec/ExtendedService.thrift +0 -25
- data/spec/Referenced.thrift +0 -44
- data/spec/ThriftNamespacedSpec.thrift +0 -53
- data/spec/ThriftSpec.thrift +0 -187
- data/spec/base_protocol_spec.rb +0 -224
- data/spec/base_transport_spec.rb +0 -387
- data/spec/binary_protocol_accelerated_spec.rb +0 -46
- data/spec/binary_protocol_spec.rb +0 -72
- data/spec/binary_protocol_spec_shared.rb +0 -445
- data/spec/bytes_spec.rb +0 -99
- data/spec/client_spec.rb +0 -166
- data/spec/compact_protocol_spec.rb +0 -196
- data/spec/constants_demo_spec.rb +0 -101
- data/spec/exception_spec.rb +0 -140
- data/spec/flat_spec.rb +0 -62
- data/spec/header_protocol_spec.rb +0 -475
- data/spec/header_transport_spec.rb +0 -386
- data/spec/http_client_spec.rb +0 -159
- data/spec/json_protocol_spec.rb +0 -552
- data/spec/namespaced_spec.rb +0 -66
- data/spec/nonblocking_server_spec.rb +0 -361
- data/spec/processor_spec.rb +0 -79
- data/spec/serializer_spec.rb +0 -66
- data/spec/server_socket_spec.rb +0 -84
- data/spec/server_spec.rb +0 -186
- data/spec/socket_spec.rb +0 -67
- data/spec/socket_spec_shared.rb +0 -167
- data/spec/spec_helper.rb +0 -69
- data/spec/ssl_server_socket_spec.rb +0 -45
- data/spec/ssl_socket_spec.rb +0 -87
- data/spec/struct_nested_containers_spec.rb +0 -190
- data/spec/struct_spec.rb +0 -397
- data/spec/support/header_protocol_helper.rb +0 -54
- data/spec/thin_http_server_spec.rb +0 -126
- data/spec/types_spec.rb +0 -117
- data/spec/union_spec.rb +0 -272
- data/spec/unix_socket_spec.rb +0 -115
- data/spec/uuid_validation_spec.rb +0 -238
- data/test/fuzz/Makefile.am +0 -173
- data/test/fuzz/README.md +0 -149
- data/test/fuzz/fuzz_common.rb +0 -95
- data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_tracer.rb +0 -28
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
@@ -22,13 +23,24 @@ module Thrift
|
|
|
22
23
|
VERSION_MASK = 0xffff0000
|
|
23
24
|
VERSION_1 = 0x80010000
|
|
24
25
|
TYPE_MASK = 0x000000ff
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
BYTE_MIN = -2**7
|
|
27
|
+
BYTE_MAX = (2**7) - 1
|
|
28
|
+
I16_MIN = -2**15
|
|
29
|
+
I16_MAX = (2**15) - 1
|
|
30
|
+
I32_MIN = -2**31
|
|
31
|
+
I32_MAX = (2**31) - 1
|
|
32
|
+
I64_MIN = -2**63
|
|
33
|
+
I64_MAX = (2**63) - 1
|
|
34
|
+
|
|
35
|
+
attr_reader :strict_read, :strict_write, :max_string_size
|
|
36
|
+
|
|
37
|
+
def initialize(trans, strict_read = true, strict_write = true, max_string_size: DEFAULT_MAX_STRING_SIZE)
|
|
38
|
+
BaseProtocol.validate_max_string_size(max_string_size)
|
|
29
39
|
super(trans)
|
|
40
|
+
@reset_message_size = trans.message_boundaries?
|
|
30
41
|
@strict_read = strict_read
|
|
31
42
|
@strict_write = strict_write
|
|
43
|
+
@max_string_size = max_string_size
|
|
32
44
|
|
|
33
45
|
# Pre-allocated read buffer for fixed-size read methods. Needs to be at least 8 bytes long for
|
|
34
46
|
# read_i64() and read_double().
|
|
@@ -36,11 +48,10 @@ module Thrift
|
|
|
36
48
|
end
|
|
37
49
|
|
|
38
50
|
def write_message_begin(name, type, seqid)
|
|
39
|
-
# this is necessary because we added (needed) bounds checking to
|
|
40
|
-
# write_i32, and 0x80010000 is too big for that.
|
|
41
51
|
if strict_write
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
raise ::TypeError, "integer argument expected" unless type.is_a?(Integer)
|
|
53
|
+
raise RangeError if type < BYTE_MIN || type > BYTE_MAX
|
|
54
|
+
trans.write([VERSION_1 | type].pack("N"))
|
|
44
55
|
write_string(name)
|
|
45
56
|
write_i32(seqid)
|
|
46
57
|
else
|
|
@@ -64,17 +75,17 @@ module Thrift
|
|
|
64
75
|
def write_map_begin(ktype, vtype, size)
|
|
65
76
|
write_byte(ktype)
|
|
66
77
|
write_byte(vtype)
|
|
67
|
-
|
|
78
|
+
write_i32_size(size)
|
|
68
79
|
end
|
|
69
80
|
|
|
70
81
|
def write_list_begin(etype, size)
|
|
71
82
|
write_byte(etype)
|
|
72
|
-
|
|
83
|
+
write_i32_size(size)
|
|
73
84
|
end
|
|
74
85
|
|
|
75
86
|
def write_set_begin(etype, size)
|
|
76
87
|
write_byte(etype)
|
|
77
|
-
|
|
88
|
+
write_i32_size(size)
|
|
78
89
|
end
|
|
79
90
|
|
|
80
91
|
def write_bool(bool)
|
|
@@ -82,44 +93,49 @@ module Thrift
|
|
|
82
93
|
end
|
|
83
94
|
|
|
84
95
|
def write_byte(byte)
|
|
85
|
-
raise
|
|
86
|
-
raise
|
|
87
|
-
|
|
96
|
+
raise "nil argument not allowed!" if byte.nil?
|
|
97
|
+
raise ::TypeError, "integer argument expected" unless byte.is_a?(Integer)
|
|
98
|
+
raise RangeError if byte < BYTE_MIN || byte > BYTE_MAX
|
|
99
|
+
trans.write([byte].pack("c"))
|
|
88
100
|
end
|
|
89
101
|
|
|
90
102
|
def write_i16(i16)
|
|
91
|
-
raise
|
|
92
|
-
|
|
103
|
+
raise "nil argument not allowed!" if i16.nil?
|
|
104
|
+
raise ::TypeError, "integer argument expected" unless i16.is_a?(Integer)
|
|
105
|
+
raise RangeError if i16 < I16_MIN || i16 > I16_MAX
|
|
106
|
+
trans.write([i16].pack("n"))
|
|
93
107
|
end
|
|
94
108
|
|
|
95
109
|
def write_i32(i32)
|
|
96
|
-
raise
|
|
97
|
-
raise
|
|
98
|
-
|
|
110
|
+
raise "nil argument not allowed!" if i32.nil?
|
|
111
|
+
raise ::TypeError, "integer argument expected" unless i32.is_a?(Integer)
|
|
112
|
+
raise RangeError if i32 < I32_MIN || i32 > I32_MAX
|
|
113
|
+
trans.write([i32].pack("N"))
|
|
99
114
|
end
|
|
100
115
|
|
|
101
116
|
def write_i64(i64)
|
|
102
|
-
raise
|
|
103
|
-
raise
|
|
117
|
+
raise "nil argument not allowed!" if i64.nil?
|
|
118
|
+
raise ::TypeError, "integer argument expected" unless i64.is_a?(Integer)
|
|
119
|
+
raise RangeError if i64 < I64_MIN || i64 > I64_MAX
|
|
104
120
|
hi = i64 >> 32
|
|
105
121
|
lo = i64 & 0xffffffff
|
|
106
|
-
trans.write([hi, lo].pack(
|
|
122
|
+
trans.write([hi, lo].pack("N2"))
|
|
107
123
|
end
|
|
108
124
|
|
|
109
125
|
def write_double(dub)
|
|
110
|
-
raise
|
|
111
|
-
trans.write([dub].pack(
|
|
126
|
+
raise "nil argument not allowed!" if dub.nil?
|
|
127
|
+
trans.write([dub].pack("G"))
|
|
112
128
|
end
|
|
113
129
|
|
|
114
130
|
def write_string(str)
|
|
115
|
-
raise
|
|
131
|
+
raise "nil argument not allowed!" if str.nil?
|
|
116
132
|
buf = Bytes.convert_to_utf8_byte_buffer(str)
|
|
117
133
|
write_binary(buf)
|
|
118
134
|
end
|
|
119
135
|
|
|
120
136
|
def write_binary(buf)
|
|
121
|
-
raise
|
|
122
|
-
|
|
137
|
+
raise "nil argument not allowed!" if buf.nil?
|
|
138
|
+
write_i32_size(buf.bytesize)
|
|
123
139
|
trans.write(buf)
|
|
124
140
|
end
|
|
125
141
|
|
|
@@ -129,10 +145,12 @@ module Thrift
|
|
|
129
145
|
end
|
|
130
146
|
|
|
131
147
|
def read_message_begin
|
|
148
|
+
trans.reset_message_size if @reset_message_size
|
|
149
|
+
|
|
132
150
|
version = read_i32
|
|
133
151
|
if version < 0
|
|
134
152
|
if (version & VERSION_MASK != VERSION_1)
|
|
135
|
-
raise ProtocolException.new(ProtocolException::BAD_VERSION,
|
|
153
|
+
raise ProtocolException.new(ProtocolException::BAD_VERSION, "Missing version identifier")
|
|
136
154
|
end
|
|
137
155
|
type = version & TYPE_MASK
|
|
138
156
|
name = read_string
|
|
@@ -140,8 +158,9 @@ module Thrift
|
|
|
140
158
|
[name, type, seqid]
|
|
141
159
|
else
|
|
142
160
|
if strict_read
|
|
143
|
-
raise ProtocolException.new(ProtocolException::BAD_VERSION,
|
|
161
|
+
raise ProtocolException.new(ProtocolException::BAD_VERSION, "No version identifier, old protocol client?")
|
|
144
162
|
end
|
|
163
|
+
check_string_size(version)
|
|
145
164
|
name = trans.read_all(version)
|
|
146
165
|
type = read_byte
|
|
147
166
|
seqid = read_i32
|
|
@@ -165,18 +184,21 @@ module Thrift
|
|
|
165
184
|
ktype = read_byte
|
|
166
185
|
vtype = read_byte
|
|
167
186
|
size = read_i32
|
|
187
|
+
raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0
|
|
168
188
|
[ktype, vtype, size]
|
|
169
189
|
end
|
|
170
190
|
|
|
171
191
|
def read_list_begin
|
|
172
192
|
etype = read_byte
|
|
173
193
|
size = read_i32
|
|
194
|
+
raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0
|
|
174
195
|
[etype, size]
|
|
175
196
|
end
|
|
176
197
|
|
|
177
198
|
def read_set_begin
|
|
178
199
|
etype = read_byte
|
|
179
200
|
size = read_i32
|
|
201
|
+
raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0
|
|
180
202
|
[etype, size]
|
|
181
203
|
end
|
|
182
204
|
|
|
@@ -195,7 +217,7 @@ module Thrift
|
|
|
195
217
|
|
|
196
218
|
def read_i16
|
|
197
219
|
trans.read_into_buffer(@rbuf, 2)
|
|
198
|
-
val
|
|
220
|
+
val = @rbuf.unpack1("n")
|
|
199
221
|
if (val > 0x7fff)
|
|
200
222
|
val = 0 - ((val - 1) ^ 0xffff)
|
|
201
223
|
end
|
|
@@ -204,7 +226,7 @@ module Thrift
|
|
|
204
226
|
|
|
205
227
|
def read_i32
|
|
206
228
|
trans.read_into_buffer(@rbuf, 4)
|
|
207
|
-
val
|
|
229
|
+
val = @rbuf.unpack1("N")
|
|
208
230
|
if (val > 0x7fffffff)
|
|
209
231
|
val = 0 - ((val - 1) ^ 0xffffffff)
|
|
210
232
|
end
|
|
@@ -213,7 +235,7 @@ module Thrift
|
|
|
213
235
|
|
|
214
236
|
def read_i64
|
|
215
237
|
trans.read_into_buffer(@rbuf, 8)
|
|
216
|
-
hi, lo = @rbuf.unpack(
|
|
238
|
+
hi, lo = @rbuf.unpack("N2")
|
|
217
239
|
if (hi > 0x7fffffff)
|
|
218
240
|
hi ^= 0xffffffff
|
|
219
241
|
lo ^= 0xffffffff
|
|
@@ -225,8 +247,7 @@ module Thrift
|
|
|
225
247
|
|
|
226
248
|
def read_double
|
|
227
249
|
trans.read_into_buffer(@rbuf, 8)
|
|
228
|
-
|
|
229
|
-
val
|
|
250
|
+
@rbuf.unpack1("G")
|
|
230
251
|
end
|
|
231
252
|
|
|
232
253
|
def read_string
|
|
@@ -236,7 +257,16 @@ module Thrift
|
|
|
236
257
|
|
|
237
258
|
def read_binary
|
|
238
259
|
size = read_i32
|
|
239
|
-
|
|
260
|
+
if size >= 0
|
|
261
|
+
check_string_size(size)
|
|
262
|
+
trans.read_all(size)
|
|
263
|
+
else
|
|
264
|
+
raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size")
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def skip_string
|
|
269
|
+
read_binary
|
|
240
270
|
end
|
|
241
271
|
|
|
242
272
|
def read_uuid
|
|
@@ -244,13 +274,26 @@ module Thrift
|
|
|
244
274
|
end
|
|
245
275
|
|
|
246
276
|
def to_s
|
|
247
|
-
"binary(#{super
|
|
277
|
+
"binary(#{super})"
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
private
|
|
281
|
+
|
|
282
|
+
def write_i32_size(size)
|
|
283
|
+
raise "nil argument not allowed!" if size.nil?
|
|
284
|
+
raise ::TypeError, "integer argument expected" unless size.is_a?(Integer)
|
|
285
|
+
raise RangeError if size < 0 || size > I32_MAX
|
|
286
|
+
trans.write([size].pack("N"))
|
|
248
287
|
end
|
|
249
288
|
end
|
|
250
289
|
|
|
251
290
|
class BinaryProtocolFactory < BaseProtocolFactory
|
|
291
|
+
def initialize(max_string_size: BaseProtocol::DEFAULT_MAX_STRING_SIZE)
|
|
292
|
+
@max_string_size = max_string_size
|
|
293
|
+
end
|
|
294
|
+
|
|
252
295
|
def get_protocol(trans)
|
|
253
|
-
|
|
296
|
+
Thrift::BinaryProtocol.new(trans, max_string_size: @max_string_size)
|
|
254
297
|
end
|
|
255
298
|
|
|
256
299
|
def to_s
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
@@ -28,11 +29,15 @@ See MemoryBuffer and BufferedTransport for examples.
|
|
|
28
29
|
|
|
29
30
|
module Thrift
|
|
30
31
|
class BinaryProtocolAcceleratedFactory < BaseProtocolFactory
|
|
32
|
+
def initialize(max_string_size: BaseProtocol::DEFAULT_MAX_STRING_SIZE)
|
|
33
|
+
@max_string_size = max_string_size
|
|
34
|
+
end
|
|
35
|
+
|
|
31
36
|
def get_protocol(trans)
|
|
32
37
|
if (defined? BinaryProtocolAccelerated)
|
|
33
|
-
BinaryProtocolAccelerated.new(trans)
|
|
38
|
+
BinaryProtocolAccelerated.new(trans, max_string_size: @max_string_size)
|
|
34
39
|
else
|
|
35
|
-
BinaryProtocol.new(trans)
|
|
40
|
+
BinaryProtocol.new(trans, max_string_size: @max_string_size)
|
|
36
41
|
end
|
|
37
42
|
end
|
|
38
43
|
|