thrift 0.8.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{README → README.md} +0 -0
- data/ext/binary_protocol_accelerated.c +33 -14
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +27 -8
- data/ext/constants.h +8 -5
- data/ext/extconf.rb +5 -1
- data/ext/memory_buffer.c +12 -9
- data/ext/protocol.c +0 -185
- data/ext/protocol.h +0 -20
- data/ext/strlcpy.h +7 -3
- data/ext/struct.c +27 -7
- data/ext/thrift_native.c +16 -11
- data/lib/thrift.rb +10 -4
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +13 -4
- data/lib/thrift/exceptions.rb +3 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +24 -6
- data/lib/thrift/protocol/base_protocol.rb +109 -12
- data/lib/thrift/protocol/binary_protocol.rb +22 -7
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +23 -6
- data/lib/thrift/protocol/json_protocol.rb +786 -0
- 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/mongrel_http_server.rb +2 -0
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thin_http_server.rb +91 -0
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/struct.rb +1 -1
- data/lib/thrift/struct_union.rb +2 -2
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +30 -20
- data/lib/thrift/transport/buffered_transport.rb +25 -11
- data/lib/thrift/transport/framed_transport.rb +20 -11
- data/lib/thrift/transport/http_client_transport.rb +16 -6
- data/lib/thrift/transport/io_stream_transport.rb +5 -2
- data/lib/thrift/transport/memory_buffer_transport.rb +10 -6
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +23 -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/ThriftSpec.thrift +52 -1
- data/spec/base_protocol_spec.rb +158 -93
- data/spec/base_transport_spec.rb +194 -157
- data/spec/binary_protocol_accelerated_spec.rb +14 -14
- data/spec/binary_protocol_spec.rb +29 -16
- data/spec/binary_protocol_spec_shared.rb +148 -65
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +45 -47
- data/spec/compact_protocol_spec.rb +36 -22
- data/spec/exception_spec.rb +79 -80
- data/spec/flat_spec.rb +62 -0
- data/spec/http_client_spec.rb +91 -16
- data/spec/json_protocol_spec.rb +552 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +26 -28
- data/spec/processor_spec.rb +29 -32
- data/spec/serializer_spec.rb +31 -33
- data/spec/server_socket_spec.rb +32 -28
- data/spec/server_spec.rb +112 -84
- data/spec/socket_spec.rb +27 -20
- data/spec/socket_spec_shared.rb +32 -32
- data/spec/spec_helper.rb +17 -11
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +159 -161
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +71 -69
- data/spec/union_spec.rb +97 -76
- data/spec/unix_socket_spec.rb +49 -41
- metadata +268 -188
- data/CHANGELOG +0 -1
- data/benchmark/gen-rb/benchmark_constants.rb +0 -10
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -9
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/thrift_spec_constants.rb +0 -10
- data/spec/gen-rb/thrift_spec_types.rb +0 -345
- data/spec/mongrel_http_server_spec.rb +0 -117
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -273
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -760
- data/test/debug_proto/gen-rb/empty_service.rb +0 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
data/ext/protocol.h
CHANGED
@@ -1,20 +0,0 @@
|
|
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
|
-
|
20
|
-
void Init_protocol();
|
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);
|
@@ -627,9 +646,6 @@ static VALUE rb_thrift_union_read(VALUE self, VALUE protocol) {
|
|
627
646
|
rb_raise(rb_eRuntimeError, "too many fields in union!");
|
628
647
|
}
|
629
648
|
|
630
|
-
// read field end
|
631
|
-
default_read_field_end(protocol);
|
632
|
-
|
633
649
|
// read struct end
|
634
650
|
default_read_struct_end(protocol);
|
635
651
|
|
@@ -654,6 +670,10 @@ static VALUE rb_thrift_union_write(VALUE self, VALUE protocol) {
|
|
654
670
|
|
655
671
|
VALUE field_info = rb_hash_aref(struct_fields, field_id);
|
656
672
|
|
673
|
+
if(NIL_P(field_info)) {
|
674
|
+
rb_raise(rb_eRuntimeError, "set_field is not valid for this union!");
|
675
|
+
}
|
676
|
+
|
657
677
|
VALUE ttype_value = rb_hash_aref(field_info, type_sym);
|
658
678
|
int ttype = FIX2INT(ttype_value);
|
659
679
|
|
data/ext/thrift_native.c
CHANGED
@@ -18,15 +18,16 @@
|
|
18
18
|
*/
|
19
19
|
|
20
20
|
#include <ruby.h>
|
21
|
+
#include <bytes.h>
|
21
22
|
#include <struct.h>
|
22
23
|
#include <binary_protocol_accelerated.h>
|
23
24
|
#include <compact_protocol.h>
|
24
|
-
#include <protocol.h>
|
25
25
|
#include <memory_buffer.h>
|
26
26
|
|
27
27
|
// cached classes/modules
|
28
28
|
VALUE rb_cSet;
|
29
29
|
VALUE thrift_module;
|
30
|
+
VALUE thrift_bytes_module;
|
30
31
|
VALUE thrift_types_module;
|
31
32
|
|
32
33
|
// TType constants
|
@@ -56,19 +57,20 @@ ID write_i32_method_id;
|
|
56
57
|
ID write_i64_method_id;
|
57
58
|
ID write_double_method_id;
|
58
59
|
ID write_string_method_id;
|
60
|
+
ID write_binary_method_id;
|
59
61
|
ID write_map_begin_method_id;
|
60
62
|
ID write_map_end_method_id;
|
61
63
|
ID write_list_begin_method_id;
|
62
64
|
ID write_list_end_method_id;
|
63
65
|
ID write_set_begin_method_id;
|
64
66
|
ID write_set_end_method_id;
|
65
|
-
ID size_method_id;
|
66
67
|
ID read_bool_method_id;
|
67
68
|
ID read_byte_method_id;
|
68
69
|
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;
|
@@ -81,15 +83,15 @@ ID read_struct_end_method_id;
|
|
81
83
|
ID read_field_begin_method_id;
|
82
84
|
ID read_field_end_method_id;
|
83
85
|
ID keys_method_id;
|
84
|
-
ID entries_method_id;
|
85
|
-
ID name_method_id;
|
86
|
-
ID sort_method_id;
|
86
|
+
ID entries_method_id;
|
87
87
|
ID write_field_stop_method_id;
|
88
88
|
ID skip_method_id;
|
89
89
|
ID write_method_id;
|
90
90
|
ID read_all_method_id;
|
91
91
|
ID read_into_buffer_method_id;
|
92
|
-
ID
|
92
|
+
ID force_binary_encoding_id;
|
93
|
+
ID convert_to_utf8_byte_buffer_id;
|
94
|
+
ID convert_to_string_id;
|
93
95
|
|
94
96
|
// constant ids
|
95
97
|
ID fields_const_id;
|
@@ -104,11 +106,13 @@ 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() {
|
110
113
|
// cached classes
|
111
114
|
thrift_module = rb_const_get(rb_cObject, rb_intern("Thrift"));
|
115
|
+
thrift_bytes_module = rb_const_get(thrift_module, rb_intern("Bytes"));
|
112
116
|
thrift_types_module = rb_const_get(thrift_module, rb_intern("Types"));
|
113
117
|
rb_cSet = rb_const_get(rb_cObject, rb_intern("Set"));
|
114
118
|
protocol_exception_class = rb_const_get(thrift_module, rb_intern("ProtocolException"));
|
@@ -139,19 +143,20 @@ void Init_thrift_native() {
|
|
139
143
|
write_i64_method_id = rb_intern("write_i64");
|
140
144
|
write_double_method_id = rb_intern("write_double");
|
141
145
|
write_string_method_id = rb_intern("write_string");
|
146
|
+
write_binary_method_id = rb_intern("write_binary");
|
142
147
|
write_map_begin_method_id = rb_intern("write_map_begin");
|
143
148
|
write_map_end_method_id = rb_intern("write_map_end");
|
144
149
|
write_list_begin_method_id = rb_intern("write_list_begin");
|
145
150
|
write_list_end_method_id = rb_intern("write_list_end");
|
146
151
|
write_set_begin_method_id = rb_intern("write_set_begin");
|
147
152
|
write_set_end_method_id = rb_intern("write_set_end");
|
148
|
-
size_method_id = rb_intern("size");
|
149
153
|
read_bool_method_id = rb_intern("read_bool");
|
150
154
|
read_byte_method_id = rb_intern("read_byte");
|
151
155
|
read_i16_method_id = rb_intern("read_i16");
|
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");
|
@@ -165,14 +170,14 @@ void Init_thrift_native() {
|
|
165
170
|
read_field_end_method_id = rb_intern("read_field_end");
|
166
171
|
keys_method_id = rb_intern("keys");
|
167
172
|
entries_method_id = rb_intern("entries");
|
168
|
-
name_method_id = rb_intern("name");
|
169
|
-
sort_method_id = rb_intern("sort");
|
170
173
|
write_field_stop_method_id = rb_intern("write_field_stop");
|
171
174
|
skip_method_id = rb_intern("skip");
|
172
175
|
write_method_id = rb_intern("write");
|
173
176
|
read_all_method_id = rb_intern("read_all");
|
174
177
|
read_into_buffer_method_id = rb_intern("read_into_buffer");
|
175
|
-
|
178
|
+
force_binary_encoding_id = rb_intern("force_binary_encoding");
|
179
|
+
convert_to_utf8_byte_buffer_id = rb_intern("convert_to_utf8_byte_buffer");
|
180
|
+
convert_to_string_id = rb_intern("convert_to_string");
|
176
181
|
|
177
182
|
// constant ids
|
178
183
|
fields_const_id = rb_intern("FIELDS");
|
@@ -187,8 +192,8 @@ 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
|
-
Init_protocol();
|
192
197
|
Init_struct();
|
193
198
|
Init_binary_protocol_accelerated();
|
194
199
|
Init_compact_protocol();
|
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,26 +6,28 @@
|
|
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.
|
22
22
|
|
23
23
|
$:.unshift File.dirname(__FILE__)
|
24
24
|
|
25
|
+
require 'thrift/bytes'
|
25
26
|
require 'thrift/core_ext'
|
26
27
|
require 'thrift/exceptions'
|
27
28
|
require 'thrift/types'
|
28
29
|
require 'thrift/processor'
|
30
|
+
require 'thrift/multiplexed_processor'
|
29
31
|
require 'thrift/client'
|
30
32
|
require 'thrift/struct'
|
31
33
|
require 'thrift/union'
|
@@ -40,12 +42,16 @@ require 'thrift/protocol/base_protocol'
|
|
40
42
|
require 'thrift/protocol/binary_protocol'
|
41
43
|
require 'thrift/protocol/binary_protocol_accelerated'
|
42
44
|
require 'thrift/protocol/compact_protocol'
|
45
|
+
require 'thrift/protocol/json_protocol'
|
46
|
+
require 'thrift/protocol/multiplexed_protocol'
|
43
47
|
|
44
48
|
# transport
|
45
49
|
require 'thrift/transport/base_transport'
|
46
50
|
require 'thrift/transport/base_server_transport'
|
47
51
|
require 'thrift/transport/socket'
|
52
|
+
require 'thrift/transport/ssl_socket'
|
48
53
|
require 'thrift/transport/server_socket'
|
54
|
+
require 'thrift/transport/ssl_server_socket'
|
49
55
|
require 'thrift/transport/unix_socket'
|
50
56
|
require 'thrift/transport/unix_server_socket'
|
51
57
|
require 'thrift/transport/buffered_transport'
|
data/lib/thrift/bytes.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
# A collection of utilities for working with bytes and byte buffers.
|
23
|
+
module Bytes
|
24
|
+
if RUBY_VERSION >= '1.9'
|
25
|
+
# Creates and empty byte buffer (String with BINARY encoding)
|
26
|
+
#
|
27
|
+
# size - The Integer size of the buffer (default: nil) to create
|
28
|
+
#
|
29
|
+
# Returns a String with BINARY encoding, filled with null characters
|
30
|
+
# if size is greater than zero
|
31
|
+
def self.empty_byte_buffer(size = nil)
|
32
|
+
if (size && size > 0)
|
33
|
+
"\0".force_encoding(Encoding::BINARY) * size
|
34
|
+
else
|
35
|
+
''.force_encoding(Encoding::BINARY)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Forces the encoding of the buffer to BINARY. If the buffer
|
40
|
+
# passed is frozen, then it will be duplicated.
|
41
|
+
#
|
42
|
+
# buffer - The String to force the encoding of.
|
43
|
+
#
|
44
|
+
# Returns the String passed with an encoding of BINARY; returned
|
45
|
+
# String may be a duplicate.
|
46
|
+
def self.force_binary_encoding(buffer)
|
47
|
+
buffer = buffer.dup if buffer.frozen?
|
48
|
+
buffer.force_encoding(Encoding::BINARY)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets the byte value of a given position in a String.
|
52
|
+
#
|
53
|
+
# string - The String to retrive the byte value from.
|
54
|
+
# index - The Integer location of the byte value to retrieve.
|
55
|
+
#
|
56
|
+
# Returns an Integer value between 0 and 255.
|
57
|
+
def self.get_string_byte(string, index)
|
58
|
+
string.getbyte(index)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Sets the byte value given to a given index in a String.
|
62
|
+
#
|
63
|
+
# string - The String to set the byte value in.
|
64
|
+
# index - The Integer location to set the byte value at.
|
65
|
+
# byte - The Integer value (0 to 255) to set in the string.
|
66
|
+
#
|
67
|
+
# Returns an Integer value of the byte value to set.
|
68
|
+
def self.set_string_byte(string, index, byte)
|
69
|
+
string.setbyte(index, byte)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Converts the given String to a UTF-8 byte buffer.
|
73
|
+
#
|
74
|
+
# string - The String to convert.
|
75
|
+
#
|
76
|
+
# Returns a new String with BINARY encoding, containing the UTF-8
|
77
|
+
# bytes of the original string.
|
78
|
+
def self.convert_to_utf8_byte_buffer(string)
|
79
|
+
if string.encoding != Encoding::UTF_8
|
80
|
+
# transcode to UTF-8
|
81
|
+
string = string.encode(Encoding::UTF_8)
|
82
|
+
else
|
83
|
+
# encoding is already UTF-8, but a duplicate is needed
|
84
|
+
string = string.dup
|
85
|
+
end
|
86
|
+
string.force_encoding(Encoding::BINARY)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Converts the given UTF-8 byte buffer into a String
|
90
|
+
#
|
91
|
+
# utf8_buffer - A String, with BINARY encoding, containing UTF-8 bytes
|
92
|
+
#
|
93
|
+
# Returns a new String with UTF-8 encoding,
|
94
|
+
def self.convert_to_string(utf8_buffer)
|
95
|
+
# duplicate the buffer, force encoding to UTF-8
|
96
|
+
utf8_buffer.dup.force_encoding(Encoding::UTF_8)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
def self.empty_byte_buffer(size = nil)
|
100
|
+
if (size && size > 0)
|
101
|
+
"\0" * size
|
102
|
+
else
|
103
|
+
''
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.force_binary_encoding(buffer)
|
108
|
+
buffer
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.get_string_byte(string, index)
|
112
|
+
string[index]
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.set_string_byte(string, index, byte)
|
116
|
+
string[index] = byte
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.convert_to_utf8_byte_buffer(string)
|
120
|
+
# This assumes $KCODE is 'UTF8'/'U', which would mean the String is already a UTF-8 byte buffer
|
121
|
+
# TODO consider handling other $KCODE values and transcoding with iconv
|
122
|
+
string
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.convert_to_string(utf8_buffer)
|
126
|
+
# See comment in 'convert_to_utf8_byte_buffer' for relevant assumptions.
|
127
|
+
utf8_buffer
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
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)
|