sessionm-thrift 0.8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/README +43 -0
- data/benchmark/Benchmark.thrift +24 -0
- data/benchmark/benchmark.rb +271 -0
- data/benchmark/client.rb +74 -0
- data/benchmark/server.rb +82 -0
- data/benchmark/thin_server.rb +44 -0
- data/ext/binary_protocol_accelerated.c +441 -0
- data/ext/binary_protocol_accelerated.h +20 -0
- data/ext/compact_protocol.c +618 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +96 -0
- data/ext/extconf.rb +30 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +131 -0
- data/ext/memory_buffer.h +20 -0
- data/ext/protocol.c +185 -0
- data/ext/protocol.h +20 -0
- data/ext/strlcpy.c +41 -0
- data/ext/strlcpy.h +30 -0
- data/ext/struct.c +691 -0
- data/ext/struct.h +25 -0
- data/ext/thrift_native.c +196 -0
- data/lib/thrift.rb +64 -0
- data/lib/thrift/client.rb +62 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/exceptions.rb +84 -0
- data/lib/thrift/processor.rb +57 -0
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/binary_protocol.rb +229 -0
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/thrift/protocol/compact_protocol.rb +426 -0
- data/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/thrift/server/base_server.rb +31 -0
- data/lib/thrift/server/mongrel_http_server.rb +58 -0
- data/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/thrift/struct.rb +237 -0
- data/lib/thrift/struct_union.rb +192 -0
- data/lib/thrift/thrift_native.rb +24 -0
- data/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/thrift/transport/base_transport.rb +107 -0
- data/lib/thrift/transport/buffered_transport.rb +108 -0
- data/lib/thrift/transport/framed_transport.rb +116 -0
- data/lib/thrift/transport/http_client_transport.rb +51 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +137 -0
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +101 -0
- data/lib/thrift/union.rb +179 -0
- data/spec/ThriftSpec.thrift +132 -0
- data/spec/base_protocol_spec.rb +160 -0
- data/spec/base_transport_spec.rb +351 -0
- data/spec/binary_protocol_accelerated_spec.rb +46 -0
- data/spec/binary_protocol_spec.rb +61 -0
- data/spec/binary_protocol_spec_shared.rb +375 -0
- data/spec/client_spec.rb +100 -0
- data/spec/compact_protocol_spec.rb +144 -0
- data/spec/exception_spec.rb +142 -0
- data/spec/http_client_spec.rb +64 -0
- data/spec/mongrel_http_server_spec.rb +117 -0
- data/spec/nonblocking_server_spec.rb +265 -0
- data/spec/processor_spec.rb +83 -0
- data/spec/serializer_spec.rb +69 -0
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +159 -0
- data/spec/socket_spec.rb +61 -0
- data/spec/socket_spec_shared.rb +104 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/struct_spec.rb +295 -0
- data/spec/types_spec.rb +116 -0
- data/spec/union_spec.rb +193 -0
- data/spec/unix_socket_spec.rb +108 -0
- metadata +247 -0
@@ -0,0 +1,44 @@
|
|
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
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
21
|
+
require 'thrift'
|
22
|
+
$:.unshift File.dirname(__FILE__) + "/gen-rb"
|
23
|
+
require 'benchmark_service'
|
24
|
+
HOST = 'localhost'
|
25
|
+
PORT = 42587
|
26
|
+
|
27
|
+
class BenchmarkHandler
|
28
|
+
# 1-based index into the fibonacci sequence
|
29
|
+
def fibonacci(n)
|
30
|
+
seq = [1, 1]
|
31
|
+
3.upto(n) do
|
32
|
+
seq << seq[-1] + seq[-2]
|
33
|
+
end
|
34
|
+
seq[n-1] # n is 1-based
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
handler = BenchmarkHandler.new
|
39
|
+
processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
|
40
|
+
transport = Thrift::ServerSocket.new(HOST, PORT)
|
41
|
+
transport_factory = Thrift::FramedTransportFactory.new
|
42
|
+
logger = Logger.new(STDERR)
|
43
|
+
logger.level = Logger::WARN
|
44
|
+
Thrift::NonblockingServer.new(processor, transport, transport_factory, nil, 20, logger).serve
|
@@ -0,0 +1,441 @@
|
|
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
|
+
#include <ruby.h>
|
21
|
+
#include <stdbool.h>
|
22
|
+
#include <stdint.h>
|
23
|
+
#include <constants.h>
|
24
|
+
#include <struct.h>
|
25
|
+
#include "macros.h"
|
26
|
+
|
27
|
+
VALUE rb_thrift_binary_proto_native_qmark(VALUE self) {
|
28
|
+
return Qtrue;
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
static int VERSION_1;
|
34
|
+
static int VERSION_MASK;
|
35
|
+
static int TYPE_MASK;
|
36
|
+
static int BAD_VERSION;
|
37
|
+
static ID rbuf_ivar_id;
|
38
|
+
|
39
|
+
static void write_byte_direct(VALUE trans, int8_t b) {
|
40
|
+
WRITE(trans, (char*)&b, 1);
|
41
|
+
}
|
42
|
+
|
43
|
+
static void write_i16_direct(VALUE trans, int16_t value) {
|
44
|
+
char data[2];
|
45
|
+
|
46
|
+
data[1] = value;
|
47
|
+
data[0] = (value >> 8);
|
48
|
+
|
49
|
+
WRITE(trans, data, 2);
|
50
|
+
}
|
51
|
+
|
52
|
+
static void write_i32_direct(VALUE trans, int32_t value) {
|
53
|
+
char data[4];
|
54
|
+
|
55
|
+
data[3] = value;
|
56
|
+
data[2] = (value >> 8);
|
57
|
+
data[1] = (value >> 16);
|
58
|
+
data[0] = (value >> 24);
|
59
|
+
|
60
|
+
WRITE(trans, data, 4);
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static void write_i64_direct(VALUE trans, int64_t value) {
|
65
|
+
char data[8];
|
66
|
+
|
67
|
+
data[7] = value;
|
68
|
+
data[6] = (value >> 8);
|
69
|
+
data[5] = (value >> 16);
|
70
|
+
data[4] = (value >> 24);
|
71
|
+
data[3] = (value >> 32);
|
72
|
+
data[2] = (value >> 40);
|
73
|
+
data[1] = (value >> 48);
|
74
|
+
data[0] = (value >> 56);
|
75
|
+
|
76
|
+
WRITE(trans, data, 8);
|
77
|
+
}
|
78
|
+
|
79
|
+
static void write_string_direct(VALUE trans, VALUE str) {
|
80
|
+
if (TYPE(str) != T_STRING) {
|
81
|
+
rb_raise(rb_eStandardError, "Value should be a string");
|
82
|
+
}
|
83
|
+
write_i32_direct(trans, RSTRING_LEN(str));
|
84
|
+
rb_funcall(trans, write_method_id, 1, str);
|
85
|
+
}
|
86
|
+
|
87
|
+
//--------------------------------
|
88
|
+
// interface writing methods
|
89
|
+
//--------------------------------
|
90
|
+
|
91
|
+
VALUE rb_thrift_binary_proto_write_message_end(VALUE self) {
|
92
|
+
return Qnil;
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE rb_thrift_binary_proto_write_struct_begin(VALUE self, VALUE name) {
|
96
|
+
return Qnil;
|
97
|
+
}
|
98
|
+
|
99
|
+
VALUE rb_thrift_binary_proto_write_struct_end(VALUE self) {
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
VALUE rb_thrift_binary_proto_write_field_end(VALUE self) {
|
104
|
+
return Qnil;
|
105
|
+
}
|
106
|
+
|
107
|
+
VALUE rb_thrift_binary_proto_write_map_end(VALUE self) {
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
VALUE rb_thrift_binary_proto_write_list_end(VALUE self) {
|
112
|
+
return Qnil;
|
113
|
+
}
|
114
|
+
|
115
|
+
VALUE rb_thrift_binary_proto_write_set_end(VALUE self) {
|
116
|
+
return Qnil;
|
117
|
+
}
|
118
|
+
|
119
|
+
VALUE rb_thrift_binary_proto_write_message_begin(VALUE self, VALUE name, VALUE type, VALUE seqid) {
|
120
|
+
VALUE trans = GET_TRANSPORT(self);
|
121
|
+
VALUE strict_write = GET_STRICT_WRITE(self);
|
122
|
+
|
123
|
+
if (strict_write == Qtrue) {
|
124
|
+
write_i32_direct(trans, VERSION_1 | FIX2INT(type));
|
125
|
+
write_string_direct(trans, name);
|
126
|
+
write_i32_direct(trans, FIX2INT(seqid));
|
127
|
+
} else {
|
128
|
+
write_string_direct(trans, name);
|
129
|
+
write_byte_direct(trans, FIX2INT(type));
|
130
|
+
write_i32_direct(trans, FIX2INT(seqid));
|
131
|
+
}
|
132
|
+
|
133
|
+
return Qnil;
|
134
|
+
}
|
135
|
+
|
136
|
+
VALUE rb_thrift_binary_proto_write_field_begin(VALUE self, VALUE name, VALUE type, VALUE id) {
|
137
|
+
VALUE trans = GET_TRANSPORT(self);
|
138
|
+
write_byte_direct(trans, FIX2INT(type));
|
139
|
+
write_i16_direct(trans, FIX2INT(id));
|
140
|
+
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
|
144
|
+
VALUE rb_thrift_binary_proto_write_field_stop(VALUE self) {
|
145
|
+
write_byte_direct(GET_TRANSPORT(self), TTYPE_STOP);
|
146
|
+
return Qnil;
|
147
|
+
}
|
148
|
+
|
149
|
+
VALUE rb_thrift_binary_proto_write_map_begin(VALUE self, VALUE ktype, VALUE vtype, VALUE size) {
|
150
|
+
VALUE trans = GET_TRANSPORT(self);
|
151
|
+
write_byte_direct(trans, FIX2INT(ktype));
|
152
|
+
write_byte_direct(trans, FIX2INT(vtype));
|
153
|
+
write_i32_direct(trans, FIX2INT(size));
|
154
|
+
|
155
|
+
return Qnil;
|
156
|
+
}
|
157
|
+
|
158
|
+
VALUE rb_thrift_binary_proto_write_list_begin(VALUE self, VALUE etype, VALUE size) {
|
159
|
+
VALUE trans = GET_TRANSPORT(self);
|
160
|
+
write_byte_direct(trans, FIX2INT(etype));
|
161
|
+
write_i32_direct(trans, FIX2INT(size));
|
162
|
+
|
163
|
+
return Qnil;
|
164
|
+
}
|
165
|
+
|
166
|
+
VALUE rb_thrift_binary_proto_write_set_begin(VALUE self, VALUE etype, VALUE size) {
|
167
|
+
rb_thrift_binary_proto_write_list_begin(self, etype, size);
|
168
|
+
return Qnil;
|
169
|
+
}
|
170
|
+
|
171
|
+
VALUE rb_thrift_binary_proto_write_bool(VALUE self, VALUE b) {
|
172
|
+
write_byte_direct(GET_TRANSPORT(self), RTEST(b) ? 1 : 0);
|
173
|
+
return Qnil;
|
174
|
+
}
|
175
|
+
|
176
|
+
VALUE rb_thrift_binary_proto_write_byte(VALUE self, VALUE byte) {
|
177
|
+
CHECK_NIL(byte);
|
178
|
+
write_byte_direct(GET_TRANSPORT(self), NUM2INT(byte));
|
179
|
+
return Qnil;
|
180
|
+
}
|
181
|
+
|
182
|
+
VALUE rb_thrift_binary_proto_write_i16(VALUE self, VALUE i16) {
|
183
|
+
CHECK_NIL(i16);
|
184
|
+
write_i16_direct(GET_TRANSPORT(self), FIX2INT(i16));
|
185
|
+
return Qnil;
|
186
|
+
}
|
187
|
+
|
188
|
+
VALUE rb_thrift_binary_proto_write_i32(VALUE self, VALUE i32) {
|
189
|
+
CHECK_NIL(i32);
|
190
|
+
write_i32_direct(GET_TRANSPORT(self), NUM2INT(i32));
|
191
|
+
return Qnil;
|
192
|
+
}
|
193
|
+
|
194
|
+
VALUE rb_thrift_binary_proto_write_i64(VALUE self, VALUE i64) {
|
195
|
+
CHECK_NIL(i64);
|
196
|
+
write_i64_direct(GET_TRANSPORT(self), NUM2LL(i64));
|
197
|
+
return Qnil;
|
198
|
+
}
|
199
|
+
|
200
|
+
VALUE rb_thrift_binary_proto_write_double(VALUE self, VALUE dub) {
|
201
|
+
CHECK_NIL(dub);
|
202
|
+
// Unfortunately, bitwise_cast doesn't work in C. Bad C!
|
203
|
+
union {
|
204
|
+
double f;
|
205
|
+
int64_t t;
|
206
|
+
} transfer;
|
207
|
+
transfer.f = RFLOAT_VALUE(rb_Float(dub));
|
208
|
+
write_i64_direct(GET_TRANSPORT(self), transfer.t);
|
209
|
+
|
210
|
+
return Qnil;
|
211
|
+
}
|
212
|
+
|
213
|
+
VALUE rb_thrift_binary_proto_write_string(VALUE self, VALUE str) {
|
214
|
+
CHECK_NIL(str);
|
215
|
+
VALUE trans = GET_TRANSPORT(self);
|
216
|
+
write_string_direct(trans, str);
|
217
|
+
return Qnil;
|
218
|
+
}
|
219
|
+
|
220
|
+
//---------------------------------------
|
221
|
+
// interface reading methods
|
222
|
+
//---------------------------------------
|
223
|
+
|
224
|
+
VALUE rb_thrift_binary_proto_read_string(VALUE self);
|
225
|
+
VALUE rb_thrift_binary_proto_read_byte(VALUE self);
|
226
|
+
VALUE rb_thrift_binary_proto_read_i32(VALUE self);
|
227
|
+
VALUE rb_thrift_binary_proto_read_i16(VALUE self);
|
228
|
+
|
229
|
+
static char read_byte_direct(VALUE self) {
|
230
|
+
VALUE byte = rb_funcall(GET_TRANSPORT(self), read_byte_method_id, 0);
|
231
|
+
return (char)(FIX2INT(byte));
|
232
|
+
}
|
233
|
+
|
234
|
+
static int16_t read_i16_direct(VALUE self) {
|
235
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
236
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(2));
|
237
|
+
return (int16_t)(((uint8_t)(RSTRING_PTR(rbuf)[1])) | ((uint16_t)((RSTRING_PTR(rbuf)[0]) << 8)));
|
238
|
+
}
|
239
|
+
|
240
|
+
static int32_t read_i32_direct(VALUE self) {
|
241
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
242
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(4));
|
243
|
+
return ((uint8_t)(RSTRING_PTR(rbuf)[3])) |
|
244
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) |
|
245
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) |
|
246
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24);
|
247
|
+
}
|
248
|
+
|
249
|
+
static int64_t read_i64_direct(VALUE self) {
|
250
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
251
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(8));
|
252
|
+
uint64_t hi = ((uint8_t)(RSTRING_PTR(rbuf)[3])) |
|
253
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) |
|
254
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) |
|
255
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24);
|
256
|
+
uint32_t lo = ((uint8_t)(RSTRING_PTR(rbuf)[7])) |
|
257
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[6])) << 8) |
|
258
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[5])) << 16) |
|
259
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[4])) << 24);
|
260
|
+
return (hi << 32) | lo;
|
261
|
+
}
|
262
|
+
|
263
|
+
static VALUE get_protocol_exception(VALUE code, VALUE message) {
|
264
|
+
VALUE args[2];
|
265
|
+
args[0] = code;
|
266
|
+
args[1] = message;
|
267
|
+
return rb_class_new_instance(2, (VALUE*)&args, protocol_exception_class);
|
268
|
+
}
|
269
|
+
|
270
|
+
VALUE rb_thrift_binary_proto_read_message_end(VALUE self) {
|
271
|
+
return Qnil;
|
272
|
+
}
|
273
|
+
|
274
|
+
VALUE rb_thift_binary_proto_read_struct_begin(VALUE self) {
|
275
|
+
return Qnil;
|
276
|
+
}
|
277
|
+
|
278
|
+
VALUE rb_thift_binary_proto_read_struct_end(VALUE self) {
|
279
|
+
return Qnil;
|
280
|
+
}
|
281
|
+
|
282
|
+
VALUE rb_thift_binary_proto_read_field_end(VALUE self) {
|
283
|
+
return Qnil;
|
284
|
+
}
|
285
|
+
|
286
|
+
VALUE rb_thift_binary_proto_read_map_end(VALUE self) {
|
287
|
+
return Qnil;
|
288
|
+
}
|
289
|
+
|
290
|
+
VALUE rb_thift_binary_proto_read_list_end(VALUE self) {
|
291
|
+
return Qnil;
|
292
|
+
}
|
293
|
+
|
294
|
+
VALUE rb_thift_binary_proto_read_set_end(VALUE self) {
|
295
|
+
return Qnil;
|
296
|
+
}
|
297
|
+
|
298
|
+
VALUE rb_thrift_binary_proto_read_message_begin(VALUE self) {
|
299
|
+
VALUE strict_read = GET_STRICT_READ(self);
|
300
|
+
VALUE name, seqid;
|
301
|
+
int type;
|
302
|
+
|
303
|
+
int version = read_i32_direct(self);
|
304
|
+
|
305
|
+
if (version < 0) {
|
306
|
+
if ((version & VERSION_MASK) != VERSION_1) {
|
307
|
+
rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("Missing version identifier")));
|
308
|
+
}
|
309
|
+
type = version & TYPE_MASK;
|
310
|
+
name = rb_thrift_binary_proto_read_string(self);
|
311
|
+
seqid = rb_thrift_binary_proto_read_i32(self);
|
312
|
+
} else {
|
313
|
+
if (strict_read == Qtrue) {
|
314
|
+
rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("No version identifier, old protocol client?")));
|
315
|
+
}
|
316
|
+
name = READ(self, version);
|
317
|
+
type = read_byte_direct(self);
|
318
|
+
seqid = rb_thrift_binary_proto_read_i32(self);
|
319
|
+
}
|
320
|
+
|
321
|
+
return rb_ary_new3(3, name, INT2FIX(type), seqid);
|
322
|
+
}
|
323
|
+
|
324
|
+
VALUE rb_thrift_binary_proto_read_field_begin(VALUE self) {
|
325
|
+
int type = read_byte_direct(self);
|
326
|
+
if (type == TTYPE_STOP) {
|
327
|
+
return rb_ary_new3(3, Qnil, INT2FIX(type), INT2FIX(0));
|
328
|
+
} else {
|
329
|
+
VALUE id = rb_thrift_binary_proto_read_i16(self);
|
330
|
+
return rb_ary_new3(3, Qnil, INT2FIX(type), id);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
VALUE rb_thrift_binary_proto_read_map_begin(VALUE self) {
|
335
|
+
VALUE ktype = rb_thrift_binary_proto_read_byte(self);
|
336
|
+
VALUE vtype = rb_thrift_binary_proto_read_byte(self);
|
337
|
+
VALUE size = rb_thrift_binary_proto_read_i32(self);
|
338
|
+
return rb_ary_new3(3, ktype, vtype, size);
|
339
|
+
}
|
340
|
+
|
341
|
+
VALUE rb_thrift_binary_proto_read_list_begin(VALUE self) {
|
342
|
+
VALUE etype = rb_thrift_binary_proto_read_byte(self);
|
343
|
+
VALUE size = rb_thrift_binary_proto_read_i32(self);
|
344
|
+
return rb_ary_new3(2, etype, size);
|
345
|
+
}
|
346
|
+
|
347
|
+
VALUE rb_thrift_binary_proto_read_set_begin(VALUE self) {
|
348
|
+
return rb_thrift_binary_proto_read_list_begin(self);
|
349
|
+
}
|
350
|
+
|
351
|
+
VALUE rb_thrift_binary_proto_read_bool(VALUE self) {
|
352
|
+
char byte = read_byte_direct(self);
|
353
|
+
return byte != 0 ? Qtrue : Qfalse;
|
354
|
+
}
|
355
|
+
|
356
|
+
VALUE rb_thrift_binary_proto_read_byte(VALUE self) {
|
357
|
+
return INT2FIX(read_byte_direct(self));
|
358
|
+
}
|
359
|
+
|
360
|
+
VALUE rb_thrift_binary_proto_read_i16(VALUE self) {
|
361
|
+
return INT2FIX(read_i16_direct(self));
|
362
|
+
}
|
363
|
+
|
364
|
+
VALUE rb_thrift_binary_proto_read_i32(VALUE self) {
|
365
|
+
return INT2NUM(read_i32_direct(self));
|
366
|
+
}
|
367
|
+
|
368
|
+
VALUE rb_thrift_binary_proto_read_i64(VALUE self) {
|
369
|
+
return LL2NUM(read_i64_direct(self));
|
370
|
+
}
|
371
|
+
|
372
|
+
VALUE rb_thrift_binary_proto_read_double(VALUE self) {
|
373
|
+
union {
|
374
|
+
double f;
|
375
|
+
int64_t t;
|
376
|
+
} transfer;
|
377
|
+
transfer.t = read_i64_direct(self);
|
378
|
+
return rb_float_new(transfer.f);
|
379
|
+
}
|
380
|
+
|
381
|
+
VALUE rb_thrift_binary_proto_read_string(VALUE self) {
|
382
|
+
int size = read_i32_direct(self);
|
383
|
+
return READ(self, size);
|
384
|
+
}
|
385
|
+
|
386
|
+
void Init_binary_protocol_accelerated() {
|
387
|
+
VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
|
388
|
+
|
389
|
+
VERSION_1 = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_1")));
|
390
|
+
VERSION_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_MASK")));
|
391
|
+
TYPE_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("TYPE_MASK")));
|
392
|
+
|
393
|
+
VALUE bpa_class = rb_define_class_under(thrift_module, "BinaryProtocolAccelerated", thrift_binary_protocol_class);
|
394
|
+
|
395
|
+
rb_define_method(bpa_class, "native?", rb_thrift_binary_proto_native_qmark, 0);
|
396
|
+
|
397
|
+
rb_define_method(bpa_class, "write_message_begin", rb_thrift_binary_proto_write_message_begin, 3);
|
398
|
+
rb_define_method(bpa_class, "write_field_begin", rb_thrift_binary_proto_write_field_begin, 3);
|
399
|
+
rb_define_method(bpa_class, "write_field_stop", rb_thrift_binary_proto_write_field_stop, 0);
|
400
|
+
rb_define_method(bpa_class, "write_map_begin", rb_thrift_binary_proto_write_map_begin, 3);
|
401
|
+
rb_define_method(bpa_class, "write_list_begin", rb_thrift_binary_proto_write_list_begin, 2);
|
402
|
+
rb_define_method(bpa_class, "write_set_begin", rb_thrift_binary_proto_write_set_begin, 2);
|
403
|
+
rb_define_method(bpa_class, "write_byte", rb_thrift_binary_proto_write_byte, 1);
|
404
|
+
rb_define_method(bpa_class, "write_bool", rb_thrift_binary_proto_write_bool, 1);
|
405
|
+
rb_define_method(bpa_class, "write_i16", rb_thrift_binary_proto_write_i16, 1);
|
406
|
+
rb_define_method(bpa_class, "write_i32", rb_thrift_binary_proto_write_i32, 1);
|
407
|
+
rb_define_method(bpa_class, "write_i64", rb_thrift_binary_proto_write_i64, 1);
|
408
|
+
rb_define_method(bpa_class, "write_double", rb_thrift_binary_proto_write_double, 1);
|
409
|
+
rb_define_method(bpa_class, "write_string", rb_thrift_binary_proto_write_string, 1);
|
410
|
+
// unused methods
|
411
|
+
rb_define_method(bpa_class, "write_message_end", rb_thrift_binary_proto_write_message_end, 0);
|
412
|
+
rb_define_method(bpa_class, "write_struct_begin", rb_thrift_binary_proto_write_struct_begin, 1);
|
413
|
+
rb_define_method(bpa_class, "write_struct_end", rb_thrift_binary_proto_write_struct_end, 0);
|
414
|
+
rb_define_method(bpa_class, "write_field_end", rb_thrift_binary_proto_write_field_end, 0);
|
415
|
+
rb_define_method(bpa_class, "write_map_end", rb_thrift_binary_proto_write_map_end, 0);
|
416
|
+
rb_define_method(bpa_class, "write_list_end", rb_thrift_binary_proto_write_list_end, 0);
|
417
|
+
rb_define_method(bpa_class, "write_set_end", rb_thrift_binary_proto_write_set_end, 0);
|
418
|
+
|
419
|
+
rb_define_method(bpa_class, "read_message_begin", rb_thrift_binary_proto_read_message_begin, 0);
|
420
|
+
rb_define_method(bpa_class, "read_field_begin", rb_thrift_binary_proto_read_field_begin, 0);
|
421
|
+
rb_define_method(bpa_class, "read_map_begin", rb_thrift_binary_proto_read_map_begin, 0);
|
422
|
+
rb_define_method(bpa_class, "read_list_begin", rb_thrift_binary_proto_read_list_begin, 0);
|
423
|
+
rb_define_method(bpa_class, "read_set_begin", rb_thrift_binary_proto_read_set_begin, 0);
|
424
|
+
rb_define_method(bpa_class, "read_byte", rb_thrift_binary_proto_read_byte, 0);
|
425
|
+
rb_define_method(bpa_class, "read_bool", rb_thrift_binary_proto_read_bool, 0);
|
426
|
+
rb_define_method(bpa_class, "read_i16", rb_thrift_binary_proto_read_i16, 0);
|
427
|
+
rb_define_method(bpa_class, "read_i32", rb_thrift_binary_proto_read_i32, 0);
|
428
|
+
rb_define_method(bpa_class, "read_i64", rb_thrift_binary_proto_read_i64, 0);
|
429
|
+
rb_define_method(bpa_class, "read_double", rb_thrift_binary_proto_read_double, 0);
|
430
|
+
rb_define_method(bpa_class, "read_string", rb_thrift_binary_proto_read_string, 0);
|
431
|
+
// unused methods
|
432
|
+
rb_define_method(bpa_class, "read_message_end", rb_thrift_binary_proto_read_message_end, 0);
|
433
|
+
rb_define_method(bpa_class, "read_struct_begin", rb_thift_binary_proto_read_struct_begin, 0);
|
434
|
+
rb_define_method(bpa_class, "read_struct_end", rb_thift_binary_proto_read_struct_end, 0);
|
435
|
+
rb_define_method(bpa_class, "read_field_end", rb_thift_binary_proto_read_field_end, 0);
|
436
|
+
rb_define_method(bpa_class, "read_map_end", rb_thift_binary_proto_read_map_end, 0);
|
437
|
+
rb_define_method(bpa_class, "read_list_end", rb_thift_binary_proto_read_list_end, 0);
|
438
|
+
rb_define_method(bpa_class, "read_set_end", rb_thift_binary_proto_read_set_end, 0);
|
439
|
+
|
440
|
+
rbuf_ivar_id = rb_intern("@rbuf");
|
441
|
+
}
|