thrift 0.9.3.0 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/struct.c +5 -1
- data/lib/thrift.rb +6 -4
- data/lib/thrift/processor.rb +10 -3
- data/lib/thrift/protocol/base_protocol.rb +11 -3
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +8 -0
- data/lib/thrift/protocol/json_protocol.rb +21 -4
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +7 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +21 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +75 -72
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +41 -42
- data/spec/compact_protocol_spec.rb +32 -17
- data/spec/exception_spec.rb +54 -54
- data/spec/flat_spec.rb +5 -5
- data/spec/http_client_spec.rb +74 -33
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +5 -5
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/processor_spec.rb +26 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/spec_helper.rb +1 -1
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +18 -18
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +47 -41
- data/spec/unix_socket_spec.rb +43 -34
- metadata +184 -148
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 537be848790427a946dbfb10294b6d7e6596396d479b0e65d3da45b4a5631d43
|
4
|
+
data.tar.gz: ff685e132618458dd33db2c4539da62439f2ab0c2981a31bb602c84c93da2615
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5dfa4cdfc317f2197d3309b097111aea74cc7c71de70f22dde133575d8bc5a6f489646c947616eef858cbef45e51f0a7564a0ada7fcc7683e37ecdaed864a3e7
|
7
|
+
data.tar.gz: cbab054a2513d0d06ece8c92a53fa0216d0709163b5cd0fcedfe185130e4b00f69ef55ab562d98285605d71353ea94122658de409013507b66dd2cd30a21b2e7
|
data/ext/struct.c
CHANGED
@@ -290,7 +290,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
|
|
290
290
|
|
291
291
|
if (TYPE(value) == T_ARRAY) {
|
292
292
|
items = value;
|
293
|
-
} else {
|
293
|
+
} else {
|
294
294
|
if (rb_cSet == CLASS_OF(value)) {
|
295
295
|
items = rb_funcall(value, entries_method_id, 0);
|
296
296
|
} else {
|
@@ -670,6 +670,10 @@ static VALUE rb_thrift_union_write(VALUE self, VALUE protocol) {
|
|
670
670
|
|
671
671
|
VALUE field_info = rb_hash_aref(struct_fields, field_id);
|
672
672
|
|
673
|
+
if(NIL_P(field_info)) {
|
674
|
+
rb_raise(rb_eRuntimeError, "set_field is not valid for this union!");
|
675
|
+
}
|
676
|
+
|
673
677
|
VALUE ttype_value = rb_hash_aref(field_info, type_sym);
|
674
678
|
int ttype = FIX2INT(ttype_value);
|
675
679
|
|
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,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
|
# 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.
|
@@ -49,7 +49,9 @@ require 'thrift/protocol/multiplexed_protocol'
|
|
49
49
|
require 'thrift/transport/base_transport'
|
50
50
|
require 'thrift/transport/base_server_transport'
|
51
51
|
require 'thrift/transport/socket'
|
52
|
+
require 'thrift/transport/ssl_socket'
|
52
53
|
require 'thrift/transport/server_socket'
|
54
|
+
require 'thrift/transport/ssl_server_socket'
|
53
55
|
require 'thrift/transport/unix_socket'
|
54
56
|
require 'thrift/transport/unix_server_socket'
|
55
57
|
require 'thrift/transport/buffered_transport'
|
data/lib/thrift/processor.rb
CHANGED
@@ -17,10 +17,18 @@
|
|
17
17
|
# under the License.
|
18
18
|
#
|
19
19
|
|
20
|
+
require 'logger'
|
21
|
+
|
20
22
|
module Thrift
|
21
23
|
module Processor
|
22
|
-
def initialize(handler)
|
24
|
+
def initialize(handler, logger=nil)
|
23
25
|
@handler = handler
|
26
|
+
if logger.nil?
|
27
|
+
@logger = Logger.new(STDERR)
|
28
|
+
@logger.level = Logger::WARN
|
29
|
+
else
|
30
|
+
@logger = logger
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
34
|
def process(iprot, oprot)
|
@@ -30,6 +38,7 @@ module Thrift
|
|
30
38
|
send("process_#{name}", seqid, iprot, oprot)
|
31
39
|
rescue => e
|
32
40
|
x = ApplicationException.new(ApplicationException::INTERNAL_ERROR, 'Internal error')
|
41
|
+
@logger.debug "Internal error : #{e.message}\n#{e.backtrace.join("\n")}"
|
33
42
|
write_error(x, oprot, name, seqid)
|
34
43
|
end
|
35
44
|
true
|
@@ -57,12 +66,10 @@ module Thrift
|
|
57
66
|
end
|
58
67
|
|
59
68
|
def write_error(err, oprot, name, seqid)
|
60
|
-
p 'write_error'
|
61
69
|
oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
|
62
70
|
err.write(oprot)
|
63
71
|
oprot.write_message_end
|
64
72
|
oprot.trans.flush
|
65
|
-
p 'write_error end'
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
@@ -323,8 +323,6 @@ module Thrift
|
|
323
323
|
|
324
324
|
def skip(type)
|
325
325
|
case type
|
326
|
-
when Types::STOP
|
327
|
-
nil
|
328
326
|
when Types::BOOL
|
329
327
|
read_bool
|
330
328
|
when Types::BYTE
|
@@ -367,13 +365,23 @@ module Thrift
|
|
367
365
|
skip(etype)
|
368
366
|
end
|
369
367
|
read_list_end
|
368
|
+
else
|
369
|
+
raise ProtocolException.new(ProtocolException::INVALID_DATA, 'Invalid data')
|
370
370
|
end
|
371
371
|
end
|
372
|
+
|
373
|
+
def to_s
|
374
|
+
"#{trans.to_s}"
|
375
|
+
end
|
372
376
|
end
|
373
377
|
|
374
378
|
class BaseProtocolFactory
|
375
379
|
def get_protocol(trans)
|
376
380
|
raise NotImplementedError
|
377
381
|
end
|
382
|
+
|
383
|
+
def to_s
|
384
|
+
"base"
|
385
|
+
end
|
378
386
|
end
|
379
|
-
end
|
387
|
+
end
|
@@ -226,12 +226,19 @@ module Thrift
|
|
226
226
|
size = read_i32
|
227
227
|
trans.read_all(size)
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
|
+
def to_s
|
231
|
+
"binary(#{super.to_s})"
|
232
|
+
end
|
230
233
|
end
|
231
234
|
|
232
235
|
class BinaryProtocolFactory < BaseProtocolFactory
|
233
236
|
def get_protocol(trans)
|
234
237
|
return Thrift::BinaryProtocol.new(trans)
|
235
238
|
end
|
239
|
+
|
240
|
+
def to_s
|
241
|
+
"binary"
|
242
|
+
end
|
236
243
|
end
|
237
244
|
end
|
@@ -345,6 +345,10 @@ module Thrift
|
|
345
345
|
size = read_varint32()
|
346
346
|
trans.read_all(size)
|
347
347
|
end
|
348
|
+
|
349
|
+
def to_s
|
350
|
+
"compact(#{super.to_s})"
|
351
|
+
end
|
348
352
|
|
349
353
|
private
|
350
354
|
|
@@ -431,5 +435,9 @@ module Thrift
|
|
431
435
|
def get_protocol(trans)
|
432
436
|
CompactProtocol.new(trans)
|
433
437
|
end
|
438
|
+
|
439
|
+
def to_s
|
440
|
+
"compact"
|
441
|
+
end
|
434
442
|
end
|
435
443
|
end
|
@@ -18,6 +18,7 @@
|
|
18
18
|
# under the License.
|
19
19
|
#
|
20
20
|
|
21
|
+
require 'base64'
|
21
22
|
|
22
23
|
module Thrift
|
23
24
|
class LookaheadReader
|
@@ -310,7 +311,7 @@ module Thrift
|
|
310
311
|
def write_json_base64(str)
|
311
312
|
@context.write(trans)
|
312
313
|
trans.write(@@kJSONStringDelimiter)
|
313
|
-
|
314
|
+
trans.write(Base64.strict_encode64(str))
|
314
315
|
trans.write(@@kJSONStringDelimiter)
|
315
316
|
end
|
316
317
|
|
@@ -332,7 +333,7 @@ module Thrift
|
|
332
333
|
# "NaN" or "Infinity" or "-Infinity".
|
333
334
|
def write_json_double(num)
|
334
335
|
@context.write(trans)
|
335
|
-
# Normalize output of
|
336
|
+
# Normalize output of thrift::to_string for NaNs and Infinities
|
336
337
|
special = false;
|
337
338
|
if (num.nan?)
|
338
339
|
special = true;
|
@@ -513,7 +514,7 @@ module Thrift
|
|
513
514
|
# The elements of this array must match up with the sequence of characters in
|
514
515
|
# escape_chars
|
515
516
|
escape_char_vals = [
|
516
|
-
|
517
|
+
"\"", "\\", "\/", "\b", "\f", "\n", "\r", "\t",
|
517
518
|
]
|
518
519
|
|
519
520
|
if !skipContext
|
@@ -546,7 +547,15 @@ module Thrift
|
|
546
547
|
|
547
548
|
# Reads a block of base64 characters, decoding it, and returns via str
|
548
549
|
def read_json_base64
|
549
|
-
read_json_string
|
550
|
+
str = read_json_string
|
551
|
+
m = str.length % 4
|
552
|
+
if m != 0
|
553
|
+
# Add missing padding
|
554
|
+
(4 - m).times do
|
555
|
+
str += '='
|
556
|
+
end
|
557
|
+
end
|
558
|
+
Base64.strict_decode64(str)
|
550
559
|
end
|
551
560
|
|
552
561
|
# Reads a sequence of characters, stopping at the first one that is not
|
@@ -759,11 +768,19 @@ module Thrift
|
|
759
768
|
def read_binary
|
760
769
|
read_json_base64
|
761
770
|
end
|
771
|
+
|
772
|
+
def to_s
|
773
|
+
"json(#{super.to_s})"
|
774
|
+
end
|
762
775
|
end
|
763
776
|
|
764
777
|
class JsonProtocolFactory < BaseProtocolFactory
|
765
778
|
def get_protocol(trans)
|
766
779
|
return Thrift::JsonProtocol.new(trans)
|
767
780
|
end
|
781
|
+
|
782
|
+
def to_s
|
783
|
+
"json"
|
784
|
+
end
|
768
785
|
end
|
769
786
|
end
|
@@ -26,6 +26,12 @@ module Thrift
|
|
26
26
|
@protocol_factory = protocol_factory ? protocol_factory : Thrift::BinaryProtocolFactory.new
|
27
27
|
end
|
28
28
|
|
29
|
-
def serve
|
29
|
+
def serve
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
"server(#{@protocol_factory.to_s}(#{@transport_factory.to_s}(#{@server_transport.to_s})))"
|
35
|
+
end
|
30
36
|
end
|
31
|
-
end
|
37
|
+
end
|
@@ -99,11 +99,19 @@ module Thrift
|
|
99
99
|
alias_method :<<, :write
|
100
100
|
|
101
101
|
def flush; end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
"base"
|
105
|
+
end
|
102
106
|
end
|
103
107
|
|
104
108
|
class BaseTransportFactory
|
105
109
|
def get_transport(trans)
|
106
110
|
return trans
|
107
111
|
end
|
112
|
+
|
113
|
+
def to_s
|
114
|
+
"base"
|
115
|
+
end
|
108
116
|
end
|
109
117
|
end
|
@@ -104,11 +104,19 @@ module Thrift
|
|
104
104
|
|
105
105
|
@transport.flush
|
106
106
|
end
|
107
|
+
|
108
|
+
def to_s
|
109
|
+
"buffered(#{@transport.to_s})"
|
110
|
+
end
|
107
111
|
end
|
108
112
|
|
109
113
|
class BufferedTransportFactory < BaseTransportFactory
|
110
114
|
def get_transport(transport)
|
111
115
|
return BufferedTransport.new(transport)
|
112
116
|
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
"buffered"
|
120
|
+
end
|
113
121
|
end
|
114
|
-
end
|
122
|
+
end
|
@@ -99,6 +99,10 @@ module Thrift
|
|
99
99
|
@wbuf = Bytes.empty_byte_buffer
|
100
100
|
end
|
101
101
|
|
102
|
+
def to_s
|
103
|
+
"framed(#{@transport.to_s})"
|
104
|
+
end
|
105
|
+
|
102
106
|
private
|
103
107
|
|
104
108
|
def read_frame
|
@@ -113,5 +117,9 @@ module Thrift
|
|
113
117
|
def get_transport(transport)
|
114
118
|
return FramedTransport.new(transport)
|
115
119
|
end
|
120
|
+
|
121
|
+
def to_s
|
122
|
+
"framed"
|
123
|
+
end
|
116
124
|
end
|
117
|
-
end
|
125
|
+
end
|
@@ -47,10 +47,17 @@ module Thrift
|
|
47
47
|
http.use_ssl = @url.scheme == 'https'
|
48
48
|
http.verify_mode = @ssl_verify_mode if @url.scheme == 'https'
|
49
49
|
resp = http.post(@url.request_uri, @outbuf, @headers)
|
50
|
+
raise TransportException.new(TransportException::UNKNOWN, "#{self.class.name} Could not connect to #{@url}, HTTP status code #{resp.code.to_i}") unless (200..299).include?(resp.code.to_i)
|
51
|
+
|
50
52
|
data = resp.body
|
51
53
|
data = Bytes.force_binary_encoding(data)
|
52
54
|
@inbuf = StringIO.new data
|
55
|
+
ensure
|
53
56
|
@outbuf = Bytes.empty_byte_buffer
|
54
57
|
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
"@{self.url}"
|
61
|
+
end
|
55
62
|
end
|
56
63
|
end
|
@@ -35,5 +35,8 @@ module Thrift
|
|
35
35
|
def write(buf); @output.write(Bytes.force_binary_encoding(buf)) end
|
36
36
|
def close; @input.close; @output.close end
|
37
37
|
def to_io; @input end # we're assuming this is used in a IO.select for reading
|
38
|
+
def to_s
|
39
|
+
"iostream(input=#{@input.to_s},output=#{@output.to_s})"
|
40
|
+
end
|
38
41
|
end
|
39
|
-
end
|
42
|
+
end
|