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