thrift 0.9.1 → 0.13.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 +6 -14
- data/{README → README.md} +0 -0
- data/ext/binary_protocol_accelerated.c +12 -12
- data/ext/compact_protocol.c +4 -2
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +1 -1
- data/ext/strlcpy.h +7 -3
- data/ext/struct.c +27 -4
- data/ext/thrift_native.c +6 -0
- data/lib/thrift.rb +8 -5
- data/lib/thrift/client.rb +13 -4
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +24 -6
- data/lib/thrift/protocol/base_protocol.rb +13 -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 +10 -1
- data/lib/thrift/protocol/json_protocol.rb +23 -6
- data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- 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 +5 -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/lib/thrift/union.rb +3 -6
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- 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 +62 -0
- data/spec/http_client_spec.rb +52 -33
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +67 -0
- 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 +4 -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 +19 -18
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +51 -40
- data/spec/unix_socket_spec.rb +43 -34
- metadata +189 -123
- data/CHANGELOG +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NWE1NzdmMDg3NjdiZGQzNjdkNzhhYzE1NTVkOGMxN2NlMzRmMmUxZDQ1NWNj
|
10
|
-
ZTUyNGM1YWRjNjM0MDViMWUzMWVjMzY5YzhiNzBhYWJmODk5OGUwODk3NjRh
|
11
|
-
NTgwNzdhZjIyYWJiZTMxZmJlODdlYzlmYjQ2MWI5ZGU2NmVmZDE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YTE1ODAyOTM5M2E4OGFlMmYyNDFjYjVkMTcyMjA4MDEzM2I1MmE3ZDg2ZmIy
|
14
|
-
MGVjYjFhM2VlOGZlM2U2YjM0YzdkZTgxYmJjNmExMDIyNTIyNDc4MGY5ZjUx
|
15
|
-
MjhiY2Y3NzM5NGIwZGE5MWMyOTY2ZmU0YWI3YzI4MTYwMzg1Nzc=
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c894aeced9c6d4f7f4e66441472dbe37603b45722cffe89007e6faa1d2771c8
|
4
|
+
data.tar.gz: 3417f5e29c4459b18933e1a6c2eb6575ce0b8c6c073bac4836043742854a8c01
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4daf374c7752cfd11fb60fa7f1a5323f026bacbff118987f7e4342bfc79e9da8cc80e2872ddf571e2b705a310fe7921bc0c011215ec5f222cee252e0ec9a513f
|
7
|
+
data.tar.gz: 4712fd01cd41fde2877df76808af17ce303656c3a003dcda92c876766aba508cdaf802511e3698ce5f4476064a435057e47493f05a2e4f928c67e16ec7554562
|
data/{README → README.md}
RENAMED
File without changes
|
@@ -283,27 +283,27 @@ VALUE rb_thrift_binary_proto_read_message_end(VALUE self) {
|
|
283
283
|
return Qnil;
|
284
284
|
}
|
285
285
|
|
286
|
-
VALUE
|
286
|
+
VALUE rb_thrift_binary_proto_read_struct_begin(VALUE self) {
|
287
287
|
return Qnil;
|
288
288
|
}
|
289
289
|
|
290
|
-
VALUE
|
290
|
+
VALUE rb_thrift_binary_proto_read_struct_end(VALUE self) {
|
291
291
|
return Qnil;
|
292
292
|
}
|
293
293
|
|
294
|
-
VALUE
|
294
|
+
VALUE rb_thrift_binary_proto_read_field_end(VALUE self) {
|
295
295
|
return Qnil;
|
296
296
|
}
|
297
297
|
|
298
|
-
VALUE
|
298
|
+
VALUE rb_thrift_binary_proto_read_map_end(VALUE self) {
|
299
299
|
return Qnil;
|
300
300
|
}
|
301
301
|
|
302
|
-
VALUE
|
302
|
+
VALUE rb_thrift_binary_proto_read_list_end(VALUE self) {
|
303
303
|
return Qnil;
|
304
304
|
}
|
305
305
|
|
306
|
-
VALUE
|
306
|
+
VALUE rb_thrift_binary_proto_read_set_end(VALUE self) {
|
307
307
|
return Qnil;
|
308
308
|
}
|
309
309
|
|
@@ -449,12 +449,12 @@ void Init_binary_protocol_accelerated() {
|
|
449
449
|
rb_define_method(bpa_class, "read_binary", rb_thrift_binary_proto_read_binary, 0);
|
450
450
|
// unused methods
|
451
451
|
rb_define_method(bpa_class, "read_message_end", rb_thrift_binary_proto_read_message_end, 0);
|
452
|
-
rb_define_method(bpa_class, "read_struct_begin",
|
453
|
-
rb_define_method(bpa_class, "read_struct_end",
|
454
|
-
rb_define_method(bpa_class, "read_field_end",
|
455
|
-
rb_define_method(bpa_class, "read_map_end",
|
456
|
-
rb_define_method(bpa_class, "read_list_end",
|
457
|
-
rb_define_method(bpa_class, "read_set_end",
|
452
|
+
rb_define_method(bpa_class, "read_struct_begin", rb_thrift_binary_proto_read_struct_begin, 0);
|
453
|
+
rb_define_method(bpa_class, "read_struct_end", rb_thrift_binary_proto_read_struct_end, 0);
|
454
|
+
rb_define_method(bpa_class, "read_field_end", rb_thrift_binary_proto_read_field_end, 0);
|
455
|
+
rb_define_method(bpa_class, "read_map_end", rb_thrift_binary_proto_read_map_end, 0);
|
456
|
+
rb_define_method(bpa_class, "read_list_end", rb_thrift_binary_proto_read_list_end, 0);
|
457
|
+
rb_define_method(bpa_class, "read_set_end", rb_thrift_binary_proto_read_set_end, 0);
|
458
458
|
|
459
459
|
rbuf_ivar_id = rb_intern("@rbuf");
|
460
460
|
}
|
data/ext/compact_protocol.c
CHANGED
@@ -40,6 +40,7 @@ static ID rbuf_ivar_id;
|
|
40
40
|
static int VERSION;
|
41
41
|
static int VERSION_MASK;
|
42
42
|
static int TYPE_MASK;
|
43
|
+
static int TYPE_BITS;
|
43
44
|
static int TYPE_SHIFT_AMOUNT;
|
44
45
|
static int PROTOCOL_ID;
|
45
46
|
|
@@ -315,7 +316,7 @@ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf) {
|
|
315
316
|
buf = force_binary_encoding(buf);
|
316
317
|
VALUE transport = GET_TRANSPORT(self);
|
317
318
|
write_varint32(transport, RSTRING_LEN(buf));
|
318
|
-
WRITE(transport,
|
319
|
+
WRITE(transport, StringValuePtr(buf), RSTRING_LEN(buf));
|
319
320
|
return Qnil;
|
320
321
|
}
|
321
322
|
|
@@ -450,7 +451,7 @@ VALUE rb_thrift_compact_proto_read_message_begin(VALUE self) {
|
|
450
451
|
rb_exc_raise(get_protocol_exception(INT2FIX(-1), rb_str_new2(buf)));
|
451
452
|
}
|
452
453
|
|
453
|
-
int8_t type = (version_and_type >> TYPE_SHIFT_AMOUNT) &
|
454
|
+
int8_t type = (version_and_type >> TYPE_SHIFT_AMOUNT) & TYPE_BITS;
|
454
455
|
int32_t seqid = read_varint64(self);
|
455
456
|
VALUE messageName = rb_thrift_compact_proto_read_string(self);
|
456
457
|
return rb_ary_new3(3, messageName, INT2FIX(type), INT2NUM(seqid));
|
@@ -570,6 +571,7 @@ static void Init_constants() {
|
|
570
571
|
VERSION = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION")));
|
571
572
|
VERSION_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION_MASK")));
|
572
573
|
TYPE_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_MASK")));
|
574
|
+
TYPE_BITS = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_BITS")));
|
573
575
|
TYPE_SHIFT_AMOUNT = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_SHIFT_AMOUNT")));
|
574
576
|
PROTOCOL_ID = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("PROTOCOL_ID")));
|
575
577
|
|
data/ext/constants.h
CHANGED
@@ -42,6 +42,7 @@ extern ID write_i32_method_id;
|
|
42
42
|
extern ID write_i64_method_id;
|
43
43
|
extern ID write_double_method_id;
|
44
44
|
extern ID write_string_method_id;
|
45
|
+
extern ID write_binary_method_id;
|
45
46
|
extern ID write_map_begin_method_id;
|
46
47
|
extern ID write_map_end_method_id;
|
47
48
|
extern ID write_list_begin_method_id;
|
@@ -54,6 +55,7 @@ extern ID read_i16_method_id;
|
|
54
55
|
extern ID read_i32_method_id;
|
55
56
|
extern ID read_i64_method_id;
|
56
57
|
extern ID read_string_method_id;
|
58
|
+
extern ID read_binary_method_id;
|
57
59
|
extern ID read_double_method_id;
|
58
60
|
extern ID read_map_begin_method_id;
|
59
61
|
extern ID read_map_end_method_id;
|
@@ -87,6 +89,7 @@ extern VALUE key_sym;
|
|
87
89
|
extern VALUE value_sym;
|
88
90
|
extern VALUE element_sym;
|
89
91
|
extern VALUE class_sym;
|
92
|
+
extern VALUE binary_sym;
|
90
93
|
|
91
94
|
extern VALUE rb_cSet;
|
92
95
|
extern VALUE thrift_module;
|
data/ext/extconf.rb
CHANGED
@@ -21,8 +21,10 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
|
21
21
|
File.open('Makefile', 'w'){|f| f.puts "all:\n\ninstall:\n" }
|
22
22
|
else
|
23
23
|
require 'mkmf'
|
24
|
+
require 'rbconfig'
|
25
|
+
|
26
|
+
$ARCH_FLAGS = RbConfig::CONFIG['CFLAGS'].scan( /(-arch )(\S+)/ ).map{|x,y| x + y + ' ' }.join('')
|
24
27
|
|
25
|
-
$ARCH_FLAGS = Config::CONFIG['CFLAGS'].scan( /(-arch )(\S+)/ ).map{|x,y| x + y + ' ' }.join('')
|
26
28
|
|
27
29
|
$CFLAGS = "-fsigned-char -g -O2 -Wall -Werror " + $ARCH_FLAGS
|
28
30
|
|
data/ext/memory_buffer.c
CHANGED
@@ -39,7 +39,7 @@ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, V
|
|
39
39
|
VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) {
|
40
40
|
VALUE buf = GET_BUF(self);
|
41
41
|
str = force_binary_encoding(str);
|
42
|
-
rb_str_buf_cat(buf,
|
42
|
+
rb_str_buf_cat(buf, StringValuePtr(str), RSTRING_LEN(str));
|
43
43
|
return Qnil;
|
44
44
|
}
|
45
45
|
|
data/ext/strlcpy.h
CHANGED
@@ -17,14 +17,18 @@
|
|
17
17
|
* under the License.
|
18
18
|
*/
|
19
19
|
|
20
|
-
|
21
20
|
#include <sys/types.h>
|
22
21
|
#include <string.h>
|
23
22
|
|
23
|
+
#ifndef __has_builtin
|
24
|
+
#define __has_builtin(x) 0
|
25
|
+
#endif
|
26
|
+
|
24
27
|
#ifndef HAVE_STRLCPY
|
25
|
-
size_t
|
26
|
-
strlcpy (char *dst, const char *src, size_t dst_sz);
|
28
|
+
size_t strlcpy (char *dst, const char *src, size_t dst_sz);
|
27
29
|
#else
|
30
|
+
#if !__has_builtin(strlcpy)
|
28
31
|
extern size_t strlcpy(char *, const char *, size_t);
|
29
32
|
#endif
|
33
|
+
#endif
|
30
34
|
|
data/ext/struct.c
CHANGED
@@ -75,6 +75,11 @@ VALUE default_write_string(VALUE protocol, VALUE value) {
|
|
75
75
|
return Qnil;
|
76
76
|
}
|
77
77
|
|
78
|
+
VALUE default_write_binary(VALUE protocol, VALUE value) {
|
79
|
+
rb_funcall(protocol, write_binary_method_id, 1, value);
|
80
|
+
return Qnil;
|
81
|
+
}
|
82
|
+
|
78
83
|
VALUE default_write_list_begin(VALUE protocol, VALUE etype, VALUE length) {
|
79
84
|
rb_funcall(protocol, write_list_begin_method_id, 2, etype, length);
|
80
85
|
return Qnil;
|
@@ -190,6 +195,10 @@ VALUE default_read_string(VALUE protocol) {
|
|
190
195
|
return rb_funcall(protocol, read_string_method_id, 0);
|
191
196
|
}
|
192
197
|
|
198
|
+
VALUE default_read_binary(VALUE protocol) {
|
199
|
+
return rb_funcall(protocol, read_binary_method_id, 0);
|
200
|
+
}
|
201
|
+
|
193
202
|
VALUE default_read_struct_begin(VALUE protocol) {
|
194
203
|
return rb_funcall(protocol, read_struct_begin_method_id, 0);
|
195
204
|
}
|
@@ -281,7 +290,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
|
|
281
290
|
|
282
291
|
if (TYPE(value) == T_ARRAY) {
|
283
292
|
items = value;
|
284
|
-
} else {
|
293
|
+
} else {
|
285
294
|
if (rb_cSet == CLASS_OF(value)) {
|
286
295
|
items = rb_funcall(value, entries_method_id, 0);
|
287
296
|
} else {
|
@@ -327,7 +336,12 @@ static void write_anything(int ttype, VALUE value, VALUE protocol, VALUE field_i
|
|
327
336
|
} else if (ttype == TTYPE_DOUBLE) {
|
328
337
|
default_write_double(protocol, value);
|
329
338
|
} else if (ttype == TTYPE_STRING) {
|
330
|
-
|
339
|
+
VALUE is_binary = rb_hash_aref(field_info, binary_sym);
|
340
|
+
if (is_binary != Qtrue) {
|
341
|
+
default_write_string(protocol, value);
|
342
|
+
} else {
|
343
|
+
default_write_binary(protocol, value);
|
344
|
+
}
|
331
345
|
} else if (IS_CONTAINER(ttype)) {
|
332
346
|
write_container(ttype, field_info, value, protocol);
|
333
347
|
} else if (ttype == TTYPE_STRUCT) {
|
@@ -430,7 +444,12 @@ static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
|
|
430
444
|
} else if (ttype == TTYPE_I64) {
|
431
445
|
result = default_read_i64(protocol);
|
432
446
|
} else if (ttype == TTYPE_STRING) {
|
433
|
-
|
447
|
+
VALUE is_binary = rb_hash_aref(field_info, binary_sym);
|
448
|
+
if (is_binary != Qtrue) {
|
449
|
+
result = default_read_string(protocol);
|
450
|
+
} else {
|
451
|
+
result = default_read_binary(protocol);
|
452
|
+
}
|
434
453
|
} else if (ttype == TTYPE_DOUBLE) {
|
435
454
|
result = default_read_double(protocol);
|
436
455
|
} else if (ttype == TTYPE_STRUCT) {
|
@@ -607,7 +626,7 @@ static VALUE rb_thrift_union_read(VALUE self, VALUE protocol) {
|
|
607
626
|
if (field_type == specified_type) {
|
608
627
|
// read the value
|
609
628
|
VALUE name = rb_hash_aref(field_info, name_sym);
|
610
|
-
rb_iv_set(self, "@setfield",
|
629
|
+
rb_iv_set(self, "@setfield", rb_str_intern(name));
|
611
630
|
rb_iv_set(self, "@value", read_anything(protocol, field_type, field_info));
|
612
631
|
} else {
|
613
632
|
rb_funcall(protocol, skip_method_id, 1, field_type_value);
|
@@ -651,6 +670,10 @@ static VALUE rb_thrift_union_write(VALUE self, VALUE protocol) {
|
|
651
670
|
|
652
671
|
VALUE field_info = rb_hash_aref(struct_fields, field_id);
|
653
672
|
|
673
|
+
if(NIL_P(field_info)) {
|
674
|
+
rb_raise(rb_eRuntimeError, "set_field is not valid for this union!");
|
675
|
+
}
|
676
|
+
|
654
677
|
VALUE ttype_value = rb_hash_aref(field_info, type_sym);
|
655
678
|
int ttype = FIX2INT(ttype_value);
|
656
679
|
|
data/ext/thrift_native.c
CHANGED
@@ -57,6 +57,7 @@ ID write_i32_method_id;
|
|
57
57
|
ID write_i64_method_id;
|
58
58
|
ID write_double_method_id;
|
59
59
|
ID write_string_method_id;
|
60
|
+
ID write_binary_method_id;
|
60
61
|
ID write_map_begin_method_id;
|
61
62
|
ID write_map_end_method_id;
|
62
63
|
ID write_list_begin_method_id;
|
@@ -69,6 +70,7 @@ ID read_i16_method_id;
|
|
69
70
|
ID read_i32_method_id;
|
70
71
|
ID read_i64_method_id;
|
71
72
|
ID read_string_method_id;
|
73
|
+
ID read_binary_method_id;
|
72
74
|
ID read_double_method_id;
|
73
75
|
ID read_map_begin_method_id;
|
74
76
|
ID read_map_end_method_id;
|
@@ -104,6 +106,7 @@ VALUE key_sym;
|
|
104
106
|
VALUE value_sym;
|
105
107
|
VALUE element_sym;
|
106
108
|
VALUE class_sym;
|
109
|
+
VALUE binary_sym;
|
107
110
|
VALUE protocol_exception_class;
|
108
111
|
|
109
112
|
void Init_thrift_native() {
|
@@ -140,6 +143,7 @@ void Init_thrift_native() {
|
|
140
143
|
write_i64_method_id = rb_intern("write_i64");
|
141
144
|
write_double_method_id = rb_intern("write_double");
|
142
145
|
write_string_method_id = rb_intern("write_string");
|
146
|
+
write_binary_method_id = rb_intern("write_binary");
|
143
147
|
write_map_begin_method_id = rb_intern("write_map_begin");
|
144
148
|
write_map_end_method_id = rb_intern("write_map_end");
|
145
149
|
write_list_begin_method_id = rb_intern("write_list_begin");
|
@@ -152,6 +156,7 @@ void Init_thrift_native() {
|
|
152
156
|
read_i32_method_id = rb_intern("read_i32");
|
153
157
|
read_i64_method_id = rb_intern("read_i64");
|
154
158
|
read_string_method_id = rb_intern("read_string");
|
159
|
+
read_binary_method_id = rb_intern("read_binary");
|
155
160
|
read_double_method_id = rb_intern("read_double");
|
156
161
|
read_map_begin_method_id = rb_intern("read_map_begin");
|
157
162
|
read_map_end_method_id = rb_intern("read_map_end");
|
@@ -187,6 +192,7 @@ void Init_thrift_native() {
|
|
187
192
|
value_sym = ID2SYM(rb_intern("value"));
|
188
193
|
element_sym = ID2SYM(rb_intern("element"));
|
189
194
|
class_sym = ID2SYM(rb_intern("class"));
|
195
|
+
binary_sym = ID2SYM(rb_intern("binary"));
|
190
196
|
|
191
197
|
Init_struct();
|
192
198
|
Init_binary_protocol_accelerated();
|
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.
|
@@ -27,6 +27,7 @@ require 'thrift/core_ext'
|
|
27
27
|
require 'thrift/exceptions'
|
28
28
|
require 'thrift/types'
|
29
29
|
require 'thrift/processor'
|
30
|
+
require 'thrift/multiplexed_processor'
|
30
31
|
require 'thrift/client'
|
31
32
|
require 'thrift/struct'
|
32
33
|
require 'thrift/union'
|
@@ -42,12 +43,15 @@ require 'thrift/protocol/binary_protocol'
|
|
42
43
|
require 'thrift/protocol/binary_protocol_accelerated'
|
43
44
|
require 'thrift/protocol/compact_protocol'
|
44
45
|
require 'thrift/protocol/json_protocol'
|
46
|
+
require 'thrift/protocol/multiplexed_protocol'
|
45
47
|
|
46
48
|
# transport
|
47
49
|
require 'thrift/transport/base_transport'
|
48
50
|
require 'thrift/transport/base_server_transport'
|
49
51
|
require 'thrift/transport/socket'
|
52
|
+
require 'thrift/transport/ssl_socket'
|
50
53
|
require 'thrift/transport/server_socket'
|
54
|
+
require 'thrift/transport/ssl_server_socket'
|
51
55
|
require 'thrift/transport/unix_socket'
|
52
56
|
require 'thrift/transport/unix_server_socket'
|
53
57
|
require 'thrift/transport/buffered_transport'
|
@@ -62,6 +66,5 @@ require 'thrift/server/nonblocking_server'
|
|
62
66
|
require 'thrift/server/simple_server'
|
63
67
|
require 'thrift/server/threaded_server'
|
64
68
|
require 'thrift/server/thread_pool_server'
|
65
|
-
require 'thrift/server/thin_http_server'
|
66
69
|
|
67
70
|
require 'thrift/thrift_native'
|
data/lib/thrift/client.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
|
module Thrift
|
21
21
|
module Client
|
@@ -27,6 +27,15 @@ module Thrift
|
|
27
27
|
|
28
28
|
def send_message(name, args_class, args = {})
|
29
29
|
@oprot.write_message_begin(name, MessageTypes::CALL, @seqid)
|
30
|
+
send_message_args(args_class, args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_oneway_message(name, args_class, args = {})
|
34
|
+
@oprot.write_message_begin(name, MessageTypes::ONEWAY, @seqid)
|
35
|
+
send_message_args(args_class, args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_message_args(args_class, args)
|
30
39
|
data = args_class.new
|
31
40
|
args.each do |k, v|
|
32
41
|
data.send("#{k.to_s}=", v)
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
require 'thrift/protocol/protocol_decorator'
|
20
|
+
require 'thrift/protocol/base_protocol'
|
21
|
+
|
22
|
+
module Thrift
|
23
|
+
class MultiplexedProcessor
|
24
|
+
def initialize
|
25
|
+
@actual_processors = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def register_processor(service_name, processor)
|
29
|
+
@actual_processors[service_name] = processor
|
30
|
+
end
|
31
|
+
|
32
|
+
def process(iprot, oprot)
|
33
|
+
name, type, seqid = iprot.read_message_begin
|
34
|
+
check_type(type)
|
35
|
+
check_separator(name)
|
36
|
+
service_name, method = name.split(':')
|
37
|
+
processor(service_name).process(StoredMessageProtocol.new(iprot, [method, type, seqid]), oprot)
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def processor(service_name)
|
43
|
+
if @actual_processors.has_key?(service_name)
|
44
|
+
@actual_processors[service_name]
|
45
|
+
else
|
46
|
+
raise Thrift::Exception.new("Service name not found: #{service_name}. Did you forget to call #{self.class.name}#register_processor?")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_type(type)
|
51
|
+
unless [MessageTypes::CALL, MessageTypes::ONEWAY].include?(type)
|
52
|
+
raise Thrift::Exception.new('This should not have happened!?')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_separator(name)
|
57
|
+
if name.count(':') < 1
|
58
|
+
raise Thrift::Exception.new("Service name not found in message name: #{name}. Did you forget to use a Thrift::Protocol::MultiplexedProtocol in your client?")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class StoredMessageProtocol < BaseProtocol
|
64
|
+
|
65
|
+
include ProtocolDecorator
|
66
|
+
|
67
|
+
def initialize(protocol, message_begin)
|
68
|
+
super(protocol)
|
69
|
+
@message_begin = message_begin
|
70
|
+
end
|
71
|
+
|
72
|
+
def read_message_begin
|
73
|
+
@message_begin
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|