upfluence-thrift 1.0.1
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 +7 -0
- data/README.md +43 -0
- data/benchmark/Benchmark.thrift +24 -0
- data/benchmark/benchmark.rb +271 -0
- data/benchmark/client.rb +74 -0
- data/benchmark/gen-rb/benchmark_constants.rb +11 -0
- data/benchmark/gen-rb/benchmark_service.rb +80 -0
- data/benchmark/gen-rb/benchmark_types.rb +10 -0
- data/benchmark/server.rb +82 -0
- data/benchmark/thin_server.rb +44 -0
- data/ext/binary_protocol_accelerated.c +460 -0
- data/ext/binary_protocol_accelerated.h +20 -0
- data/ext/bytes.c +36 -0
- data/ext/bytes.h +31 -0
- data/ext/compact_protocol.c +637 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +99 -0
- data/ext/extconf.rb +34 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +134 -0
- data/ext/memory_buffer.h +20 -0
- data/ext/protocol.c +0 -0
- data/ext/protocol.h +0 -0
- data/ext/strlcpy.c +41 -0
- data/ext/strlcpy.h +34 -0
- data/ext/struct.c +707 -0
- data/ext/struct.h +25 -0
- data/ext/thrift_native.c +201 -0
- data/lib/thrift.rb +68 -0
- data/lib/thrift/bytes.rb +131 -0
- data/lib/thrift/client.rb +71 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/exceptions.rb +87 -0
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +57 -0
- data/lib/thrift/protocol/base_protocol.rb +379 -0
- data/lib/thrift/protocol/binary_protocol.rb +237 -0
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/thrift/protocol/compact_protocol.rb +435 -0
- data/lib/thrift/protocol/json_protocol.rb +769 -0
- data/lib/thrift/protocol/multiplexed_protocol.rb +40 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -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 +60 -0
- data/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/thrift/server/rack_application.rb +61 -0
- data/lib/thrift/server/simple_server.rb +43 -0
- data/lib/thrift/server/thin_http_server.rb +51 -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 +109 -0
- data/lib/thrift/transport/buffered_transport.rb +114 -0
- data/lib/thrift/transport/framed_transport.rb +117 -0
- data/lib/thrift/transport/http_client_transport.rb +56 -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 +139 -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/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 +183 -0
- data/spec/base_protocol_spec.rb +217 -0
- data/spec/base_transport_spec.rb +350 -0
- data/spec/binary_protocol_accelerated_spec.rb +42 -0
- data/spec/binary_protocol_spec.rb +66 -0
- data/spec/binary_protocol_spec_shared.rb +455 -0
- data/spec/bytes_spec.rb +160 -0
- data/spec/client_spec.rb +99 -0
- data/spec/compact_protocol_spec.rb +143 -0
- data/spec/exception_spec.rb +141 -0
- data/spec/flat_spec.rb +62 -0
- data/spec/gen-rb/base/base_service.rb +80 -0
- data/spec/gen-rb/base/base_service_constants.rb +11 -0
- data/spec/gen-rb/base/base_service_types.rb +26 -0
- data/spec/gen-rb/extended/extended_service.rb +78 -0
- data/spec/gen-rb/extended/extended_service_constants.rb +11 -0
- data/spec/gen-rb/extended/extended_service_types.rb +12 -0
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/flat/referenced_constants.rb +11 -0
- data/spec/gen-rb/flat/referenced_types.rb +17 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +272 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +28 -0
- data/spec/gen-rb/nonblocking_service.rb +272 -0
- data/spec/gen-rb/other_namespace/referenced_constants.rb +11 -0
- data/spec/gen-rb/other_namespace/referenced_types.rb +17 -0
- data/spec/gen-rb/thrift_spec_constants.rb +11 -0
- data/spec/gen-rb/thrift_spec_types.rb +538 -0
- data/spec/http_client_spec.rb +120 -0
- data/spec/json_protocol_spec.rb +513 -0
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +263 -0
- data/spec/processor_spec.rb +80 -0
- data/spec/serializer_spec.rb +67 -0
- data/spec/server_socket_spec.rb +79 -0
- data/spec/server_spec.rb +147 -0
- data/spec/socket_spec.rb +61 -0
- data/spec/socket_spec_shared.rb +104 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/struct_nested_containers_spec.rb +191 -0
- data/spec/struct_spec.rb +293 -0
- data/spec/thin_http_server_spec.rb +141 -0
- data/spec/types_spec.rb +115 -0
- data/spec/union_spec.rb +203 -0
- data/spec/unix_socket_spec.rb +107 -0
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +274 -0
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +761 -0
- data/test/debug_proto/gen-rb/empty_service.rb +24 -0
- data/test/debug_proto/gen-rb/inherited.rb +79 -0
- data/test/debug_proto/gen-rb/reverse_order_service.rb +82 -0
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +81 -0
- data/test/debug_proto/gen-rb/srv.rb +330 -0
- metadata +388 -0
data/benchmark/server.rb
ADDED
@@ -0,0 +1,82 @@
|
|
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
|
+
|
25
|
+
module Server
|
26
|
+
include Thrift
|
27
|
+
|
28
|
+
class BenchmarkHandler
|
29
|
+
# 1-based index into the fibonacci sequence
|
30
|
+
def fibonacci(n)
|
31
|
+
seq = [1, 1]
|
32
|
+
3.upto(n) do
|
33
|
+
seq << seq[-1] + seq[-2]
|
34
|
+
end
|
35
|
+
seq[n-1] # n is 1-based
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.start_server(host, port, serverClass)
|
40
|
+
handler = BenchmarkHandler.new
|
41
|
+
processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
|
42
|
+
transport = ServerSocket.new(host, port)
|
43
|
+
transport_factory = FramedTransportFactory.new
|
44
|
+
args = [processor, transport, transport_factory, nil, 20]
|
45
|
+
if serverClass == NonblockingServer
|
46
|
+
logger = Logger.new(STDERR)
|
47
|
+
logger.level = Logger::WARN
|
48
|
+
args << logger
|
49
|
+
end
|
50
|
+
server = serverClass.new(*args)
|
51
|
+
@server_thread = Thread.new do
|
52
|
+
server.serve
|
53
|
+
end
|
54
|
+
@server = server
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.shutdown
|
58
|
+
return if @server.nil?
|
59
|
+
if @server.respond_to? :shutdown
|
60
|
+
@server.shutdown
|
61
|
+
else
|
62
|
+
@server_thread.kill
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def resolve_const(const)
|
68
|
+
const and const.split('::').inject(Object) { |k,c| k.const_get(c) }
|
69
|
+
end
|
70
|
+
|
71
|
+
host, port, serverklass = ARGV
|
72
|
+
|
73
|
+
Server.start_server(host, port.to_i, resolve_const(serverklass))
|
74
|
+
|
75
|
+
# let our host know that the interpreter has started
|
76
|
+
# ideally we'd wait until the server was serving, but we don't have a hook for that
|
77
|
+
Marshal.dump(:started, STDOUT)
|
78
|
+
STDOUT.flush
|
79
|
+
|
80
|
+
Marshal.load(STDIN) # wait until we're instructed to shut down
|
81
|
+
|
82
|
+
Server.shutdown
|
@@ -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,460 @@
|
|
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
|
+
#include <bytes.h>
|
27
|
+
|
28
|
+
VALUE rb_thrift_binary_proto_native_qmark(VALUE self) {
|
29
|
+
return Qtrue;
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
static int VERSION_1;
|
35
|
+
static int VERSION_MASK;
|
36
|
+
static int TYPE_MASK;
|
37
|
+
static int BAD_VERSION;
|
38
|
+
static ID rbuf_ivar_id;
|
39
|
+
|
40
|
+
static void write_byte_direct(VALUE trans, int8_t b) {
|
41
|
+
WRITE(trans, (char*)&b, 1);
|
42
|
+
}
|
43
|
+
|
44
|
+
static void write_i16_direct(VALUE trans, int16_t value) {
|
45
|
+
char data[2];
|
46
|
+
|
47
|
+
data[1] = value;
|
48
|
+
data[0] = (value >> 8);
|
49
|
+
|
50
|
+
WRITE(trans, data, 2);
|
51
|
+
}
|
52
|
+
|
53
|
+
static void write_i32_direct(VALUE trans, int32_t value) {
|
54
|
+
char data[4];
|
55
|
+
|
56
|
+
data[3] = value;
|
57
|
+
data[2] = (value >> 8);
|
58
|
+
data[1] = (value >> 16);
|
59
|
+
data[0] = (value >> 24);
|
60
|
+
|
61
|
+
WRITE(trans, data, 4);
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
static void write_i64_direct(VALUE trans, int64_t value) {
|
66
|
+
char data[8];
|
67
|
+
|
68
|
+
data[7] = value;
|
69
|
+
data[6] = (value >> 8);
|
70
|
+
data[5] = (value >> 16);
|
71
|
+
data[4] = (value >> 24);
|
72
|
+
data[3] = (value >> 32);
|
73
|
+
data[2] = (value >> 40);
|
74
|
+
data[1] = (value >> 48);
|
75
|
+
data[0] = (value >> 56);
|
76
|
+
|
77
|
+
WRITE(trans, data, 8);
|
78
|
+
}
|
79
|
+
|
80
|
+
static void write_string_direct(VALUE trans, VALUE str) {
|
81
|
+
if (TYPE(str) != T_STRING) {
|
82
|
+
rb_raise(rb_eStandardError, "Value should be a string");
|
83
|
+
}
|
84
|
+
str = convert_to_utf8_byte_buffer(str);
|
85
|
+
write_i32_direct(trans, RSTRING_LEN(str));
|
86
|
+
rb_funcall(trans, write_method_id, 1, str);
|
87
|
+
}
|
88
|
+
|
89
|
+
//--------------------------------
|
90
|
+
// interface writing methods
|
91
|
+
//--------------------------------
|
92
|
+
|
93
|
+
VALUE rb_thrift_binary_proto_write_message_end(VALUE self) {
|
94
|
+
return Qnil;
|
95
|
+
}
|
96
|
+
|
97
|
+
VALUE rb_thrift_binary_proto_write_struct_begin(VALUE self, VALUE name) {
|
98
|
+
return Qnil;
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE rb_thrift_binary_proto_write_struct_end(VALUE self) {
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
VALUE rb_thrift_binary_proto_write_field_end(VALUE self) {
|
106
|
+
return Qnil;
|
107
|
+
}
|
108
|
+
|
109
|
+
VALUE rb_thrift_binary_proto_write_map_end(VALUE self) {
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE rb_thrift_binary_proto_write_list_end(VALUE self) {
|
114
|
+
return Qnil;
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE rb_thrift_binary_proto_write_set_end(VALUE self) {
|
118
|
+
return Qnil;
|
119
|
+
}
|
120
|
+
|
121
|
+
VALUE rb_thrift_binary_proto_write_message_begin(VALUE self, VALUE name, VALUE type, VALUE seqid) {
|
122
|
+
VALUE trans = GET_TRANSPORT(self);
|
123
|
+
VALUE strict_write = GET_STRICT_WRITE(self);
|
124
|
+
|
125
|
+
if (strict_write == Qtrue) {
|
126
|
+
write_i32_direct(trans, VERSION_1 | FIX2INT(type));
|
127
|
+
write_string_direct(trans, name);
|
128
|
+
write_i32_direct(trans, FIX2INT(seqid));
|
129
|
+
} else {
|
130
|
+
write_string_direct(trans, name);
|
131
|
+
write_byte_direct(trans, FIX2INT(type));
|
132
|
+
write_i32_direct(trans, FIX2INT(seqid));
|
133
|
+
}
|
134
|
+
|
135
|
+
return Qnil;
|
136
|
+
}
|
137
|
+
|
138
|
+
VALUE rb_thrift_binary_proto_write_field_begin(VALUE self, VALUE name, VALUE type, VALUE id) {
|
139
|
+
VALUE trans = GET_TRANSPORT(self);
|
140
|
+
write_byte_direct(trans, FIX2INT(type));
|
141
|
+
write_i16_direct(trans, FIX2INT(id));
|
142
|
+
|
143
|
+
return Qnil;
|
144
|
+
}
|
145
|
+
|
146
|
+
VALUE rb_thrift_binary_proto_write_field_stop(VALUE self) {
|
147
|
+
write_byte_direct(GET_TRANSPORT(self), TTYPE_STOP);
|
148
|
+
return Qnil;
|
149
|
+
}
|
150
|
+
|
151
|
+
VALUE rb_thrift_binary_proto_write_map_begin(VALUE self, VALUE ktype, VALUE vtype, VALUE size) {
|
152
|
+
VALUE trans = GET_TRANSPORT(self);
|
153
|
+
write_byte_direct(trans, FIX2INT(ktype));
|
154
|
+
write_byte_direct(trans, FIX2INT(vtype));
|
155
|
+
write_i32_direct(trans, FIX2INT(size));
|
156
|
+
|
157
|
+
return Qnil;
|
158
|
+
}
|
159
|
+
|
160
|
+
VALUE rb_thrift_binary_proto_write_list_begin(VALUE self, VALUE etype, VALUE size) {
|
161
|
+
VALUE trans = GET_TRANSPORT(self);
|
162
|
+
write_byte_direct(trans, FIX2INT(etype));
|
163
|
+
write_i32_direct(trans, FIX2INT(size));
|
164
|
+
|
165
|
+
return Qnil;
|
166
|
+
}
|
167
|
+
|
168
|
+
VALUE rb_thrift_binary_proto_write_set_begin(VALUE self, VALUE etype, VALUE size) {
|
169
|
+
rb_thrift_binary_proto_write_list_begin(self, etype, size);
|
170
|
+
return Qnil;
|
171
|
+
}
|
172
|
+
|
173
|
+
VALUE rb_thrift_binary_proto_write_bool(VALUE self, VALUE b) {
|
174
|
+
write_byte_direct(GET_TRANSPORT(self), RTEST(b) ? 1 : 0);
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
|
178
|
+
VALUE rb_thrift_binary_proto_write_byte(VALUE self, VALUE byte) {
|
179
|
+
CHECK_NIL(byte);
|
180
|
+
write_byte_direct(GET_TRANSPORT(self), NUM2INT(byte));
|
181
|
+
return Qnil;
|
182
|
+
}
|
183
|
+
|
184
|
+
VALUE rb_thrift_binary_proto_write_i16(VALUE self, VALUE i16) {
|
185
|
+
CHECK_NIL(i16);
|
186
|
+
write_i16_direct(GET_TRANSPORT(self), FIX2INT(i16));
|
187
|
+
return Qnil;
|
188
|
+
}
|
189
|
+
|
190
|
+
VALUE rb_thrift_binary_proto_write_i32(VALUE self, VALUE i32) {
|
191
|
+
CHECK_NIL(i32);
|
192
|
+
write_i32_direct(GET_TRANSPORT(self), NUM2INT(i32));
|
193
|
+
return Qnil;
|
194
|
+
}
|
195
|
+
|
196
|
+
VALUE rb_thrift_binary_proto_write_i64(VALUE self, VALUE i64) {
|
197
|
+
CHECK_NIL(i64);
|
198
|
+
write_i64_direct(GET_TRANSPORT(self), NUM2LL(i64));
|
199
|
+
return Qnil;
|
200
|
+
}
|
201
|
+
|
202
|
+
VALUE rb_thrift_binary_proto_write_double(VALUE self, VALUE dub) {
|
203
|
+
CHECK_NIL(dub);
|
204
|
+
// Unfortunately, bitwise_cast doesn't work in C. Bad C!
|
205
|
+
union {
|
206
|
+
double f;
|
207
|
+
int64_t t;
|
208
|
+
} transfer;
|
209
|
+
transfer.f = RFLOAT_VALUE(rb_Float(dub));
|
210
|
+
write_i64_direct(GET_TRANSPORT(self), transfer.t);
|
211
|
+
|
212
|
+
return Qnil;
|
213
|
+
}
|
214
|
+
|
215
|
+
VALUE rb_thrift_binary_proto_write_string(VALUE self, VALUE str) {
|
216
|
+
CHECK_NIL(str);
|
217
|
+
VALUE trans = GET_TRANSPORT(self);
|
218
|
+
write_string_direct(trans, str);
|
219
|
+
return Qnil;
|
220
|
+
}
|
221
|
+
|
222
|
+
VALUE rb_thrift_binary_proto_write_binary(VALUE self, VALUE buf) {
|
223
|
+
CHECK_NIL(buf);
|
224
|
+
VALUE trans = GET_TRANSPORT(self);
|
225
|
+
buf = force_binary_encoding(buf);
|
226
|
+
write_i32_direct(trans, RSTRING_LEN(buf));
|
227
|
+
rb_funcall(trans, write_method_id, 1, buf);
|
228
|
+
return Qnil;
|
229
|
+
}
|
230
|
+
|
231
|
+
//---------------------------------------
|
232
|
+
// interface reading methods
|
233
|
+
//---------------------------------------
|
234
|
+
|
235
|
+
VALUE rb_thrift_binary_proto_read_string(VALUE self);
|
236
|
+
VALUE rb_thrift_binary_proto_read_binary(VALUE self);
|
237
|
+
VALUE rb_thrift_binary_proto_read_byte(VALUE self);
|
238
|
+
VALUE rb_thrift_binary_proto_read_i32(VALUE self);
|
239
|
+
VALUE rb_thrift_binary_proto_read_i16(VALUE self);
|
240
|
+
|
241
|
+
static char read_byte_direct(VALUE self) {
|
242
|
+
VALUE byte = rb_funcall(GET_TRANSPORT(self), read_byte_method_id, 0);
|
243
|
+
return (char)(FIX2INT(byte));
|
244
|
+
}
|
245
|
+
|
246
|
+
static int16_t read_i16_direct(VALUE self) {
|
247
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
248
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(2));
|
249
|
+
return (int16_t)(((uint8_t)(RSTRING_PTR(rbuf)[1])) | ((uint16_t)((RSTRING_PTR(rbuf)[0]) << 8)));
|
250
|
+
}
|
251
|
+
|
252
|
+
static int32_t read_i32_direct(VALUE self) {
|
253
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
254
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(4));
|
255
|
+
return ((uint8_t)(RSTRING_PTR(rbuf)[3])) |
|
256
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) |
|
257
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) |
|
258
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24);
|
259
|
+
}
|
260
|
+
|
261
|
+
static int64_t read_i64_direct(VALUE self) {
|
262
|
+
VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id);
|
263
|
+
rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(8));
|
264
|
+
uint64_t hi = ((uint8_t)(RSTRING_PTR(rbuf)[3])) |
|
265
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) |
|
266
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) |
|
267
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24);
|
268
|
+
uint32_t lo = ((uint8_t)(RSTRING_PTR(rbuf)[7])) |
|
269
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[6])) << 8) |
|
270
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[5])) << 16) |
|
271
|
+
(((uint8_t)(RSTRING_PTR(rbuf)[4])) << 24);
|
272
|
+
return (hi << 32) | lo;
|
273
|
+
}
|
274
|
+
|
275
|
+
static VALUE get_protocol_exception(VALUE code, VALUE message) {
|
276
|
+
VALUE args[2];
|
277
|
+
args[0] = code;
|
278
|
+
args[1] = message;
|
279
|
+
return rb_class_new_instance(2, (VALUE*)&args, protocol_exception_class);
|
280
|
+
}
|
281
|
+
|
282
|
+
VALUE rb_thrift_binary_proto_read_message_end(VALUE self) {
|
283
|
+
return Qnil;
|
284
|
+
}
|
285
|
+
|
286
|
+
VALUE rb_thrift_binary_proto_read_struct_begin(VALUE self) {
|
287
|
+
return Qnil;
|
288
|
+
}
|
289
|
+
|
290
|
+
VALUE rb_thrift_binary_proto_read_struct_end(VALUE self) {
|
291
|
+
return Qnil;
|
292
|
+
}
|
293
|
+
|
294
|
+
VALUE rb_thrift_binary_proto_read_field_end(VALUE self) {
|
295
|
+
return Qnil;
|
296
|
+
}
|
297
|
+
|
298
|
+
VALUE rb_thrift_binary_proto_read_map_end(VALUE self) {
|
299
|
+
return Qnil;
|
300
|
+
}
|
301
|
+
|
302
|
+
VALUE rb_thrift_binary_proto_read_list_end(VALUE self) {
|
303
|
+
return Qnil;
|
304
|
+
}
|
305
|
+
|
306
|
+
VALUE rb_thrift_binary_proto_read_set_end(VALUE self) {
|
307
|
+
return Qnil;
|
308
|
+
}
|
309
|
+
|
310
|
+
VALUE rb_thrift_binary_proto_read_message_begin(VALUE self) {
|
311
|
+
VALUE strict_read = GET_STRICT_READ(self);
|
312
|
+
VALUE name, seqid;
|
313
|
+
int type;
|
314
|
+
|
315
|
+
int version = read_i32_direct(self);
|
316
|
+
|
317
|
+
if (version < 0) {
|
318
|
+
if ((version & VERSION_MASK) != VERSION_1) {
|
319
|
+
rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("Missing version identifier")));
|
320
|
+
}
|
321
|
+
type = version & TYPE_MASK;
|
322
|
+
name = rb_thrift_binary_proto_read_string(self);
|
323
|
+
seqid = rb_thrift_binary_proto_read_i32(self);
|
324
|
+
} else {
|
325
|
+
if (strict_read == Qtrue) {
|
326
|
+
rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("No version identifier, old protocol client?")));
|
327
|
+
}
|
328
|
+
name = READ(self, version);
|
329
|
+
type = read_byte_direct(self);
|
330
|
+
seqid = rb_thrift_binary_proto_read_i32(self);
|
331
|
+
}
|
332
|
+
|
333
|
+
return rb_ary_new3(3, name, INT2FIX(type), seqid);
|
334
|
+
}
|
335
|
+
|
336
|
+
VALUE rb_thrift_binary_proto_read_field_begin(VALUE self) {
|
337
|
+
int type = read_byte_direct(self);
|
338
|
+
if (type == TTYPE_STOP) {
|
339
|
+
return rb_ary_new3(3, Qnil, INT2FIX(type), INT2FIX(0));
|
340
|
+
} else {
|
341
|
+
VALUE id = rb_thrift_binary_proto_read_i16(self);
|
342
|
+
return rb_ary_new3(3, Qnil, INT2FIX(type), id);
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
VALUE rb_thrift_binary_proto_read_map_begin(VALUE self) {
|
347
|
+
VALUE ktype = rb_thrift_binary_proto_read_byte(self);
|
348
|
+
VALUE vtype = rb_thrift_binary_proto_read_byte(self);
|
349
|
+
VALUE size = rb_thrift_binary_proto_read_i32(self);
|
350
|
+
return rb_ary_new3(3, ktype, vtype, size);
|
351
|
+
}
|
352
|
+
|
353
|
+
VALUE rb_thrift_binary_proto_read_list_begin(VALUE self) {
|
354
|
+
VALUE etype = rb_thrift_binary_proto_read_byte(self);
|
355
|
+
VALUE size = rb_thrift_binary_proto_read_i32(self);
|
356
|
+
return rb_ary_new3(2, etype, size);
|
357
|
+
}
|
358
|
+
|
359
|
+
VALUE rb_thrift_binary_proto_read_set_begin(VALUE self) {
|
360
|
+
return rb_thrift_binary_proto_read_list_begin(self);
|
361
|
+
}
|
362
|
+
|
363
|
+
VALUE rb_thrift_binary_proto_read_bool(VALUE self) {
|
364
|
+
char byte = read_byte_direct(self);
|
365
|
+
return byte != 0 ? Qtrue : Qfalse;
|
366
|
+
}
|
367
|
+
|
368
|
+
VALUE rb_thrift_binary_proto_read_byte(VALUE self) {
|
369
|
+
return INT2FIX(read_byte_direct(self));
|
370
|
+
}
|
371
|
+
|
372
|
+
VALUE rb_thrift_binary_proto_read_i16(VALUE self) {
|
373
|
+
return INT2FIX(read_i16_direct(self));
|
374
|
+
}
|
375
|
+
|
376
|
+
VALUE rb_thrift_binary_proto_read_i32(VALUE self) {
|
377
|
+
return INT2NUM(read_i32_direct(self));
|
378
|
+
}
|
379
|
+
|
380
|
+
VALUE rb_thrift_binary_proto_read_i64(VALUE self) {
|
381
|
+
return LL2NUM(read_i64_direct(self));
|
382
|
+
}
|
383
|
+
|
384
|
+
VALUE rb_thrift_binary_proto_read_double(VALUE self) {
|
385
|
+
union {
|
386
|
+
double f;
|
387
|
+
int64_t t;
|
388
|
+
} transfer;
|
389
|
+
transfer.t = read_i64_direct(self);
|
390
|
+
return rb_float_new(transfer.f);
|
391
|
+
}
|
392
|
+
|
393
|
+
VALUE rb_thrift_binary_proto_read_string(VALUE self) {
|
394
|
+
VALUE buffer = rb_thrift_binary_proto_read_binary(self);
|
395
|
+
return convert_to_string(buffer);
|
396
|
+
}
|
397
|
+
|
398
|
+
VALUE rb_thrift_binary_proto_read_binary(VALUE self) {
|
399
|
+
int size = read_i32_direct(self);
|
400
|
+
return READ(self, size);
|
401
|
+
}
|
402
|
+
|
403
|
+
void Init_binary_protocol_accelerated() {
|
404
|
+
VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
|
405
|
+
|
406
|
+
VERSION_1 = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_1")));
|
407
|
+
VERSION_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_MASK")));
|
408
|
+
TYPE_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("TYPE_MASK")));
|
409
|
+
|
410
|
+
VALUE bpa_class = rb_define_class_under(thrift_module, "BinaryProtocolAccelerated", thrift_binary_protocol_class);
|
411
|
+
|
412
|
+
rb_define_method(bpa_class, "native?", rb_thrift_binary_proto_native_qmark, 0);
|
413
|
+
|
414
|
+
rb_define_method(bpa_class, "write_message_begin", rb_thrift_binary_proto_write_message_begin, 3);
|
415
|
+
rb_define_method(bpa_class, "write_field_begin", rb_thrift_binary_proto_write_field_begin, 3);
|
416
|
+
rb_define_method(bpa_class, "write_field_stop", rb_thrift_binary_proto_write_field_stop, 0);
|
417
|
+
rb_define_method(bpa_class, "write_map_begin", rb_thrift_binary_proto_write_map_begin, 3);
|
418
|
+
rb_define_method(bpa_class, "write_list_begin", rb_thrift_binary_proto_write_list_begin, 2);
|
419
|
+
rb_define_method(bpa_class, "write_set_begin", rb_thrift_binary_proto_write_set_begin, 2);
|
420
|
+
rb_define_method(bpa_class, "write_byte", rb_thrift_binary_proto_write_byte, 1);
|
421
|
+
rb_define_method(bpa_class, "write_bool", rb_thrift_binary_proto_write_bool, 1);
|
422
|
+
rb_define_method(bpa_class, "write_i16", rb_thrift_binary_proto_write_i16, 1);
|
423
|
+
rb_define_method(bpa_class, "write_i32", rb_thrift_binary_proto_write_i32, 1);
|
424
|
+
rb_define_method(bpa_class, "write_i64", rb_thrift_binary_proto_write_i64, 1);
|
425
|
+
rb_define_method(bpa_class, "write_double", rb_thrift_binary_proto_write_double, 1);
|
426
|
+
rb_define_method(bpa_class, "write_string", rb_thrift_binary_proto_write_string, 1);
|
427
|
+
rb_define_method(bpa_class, "write_binary", rb_thrift_binary_proto_write_binary, 1);
|
428
|
+
// unused methods
|
429
|
+
rb_define_method(bpa_class, "write_message_end", rb_thrift_binary_proto_write_message_end, 0);
|
430
|
+
rb_define_method(bpa_class, "write_struct_begin", rb_thrift_binary_proto_write_struct_begin, 1);
|
431
|
+
rb_define_method(bpa_class, "write_struct_end", rb_thrift_binary_proto_write_struct_end, 0);
|
432
|
+
rb_define_method(bpa_class, "write_field_end", rb_thrift_binary_proto_write_field_end, 0);
|
433
|
+
rb_define_method(bpa_class, "write_map_end", rb_thrift_binary_proto_write_map_end, 0);
|
434
|
+
rb_define_method(bpa_class, "write_list_end", rb_thrift_binary_proto_write_list_end, 0);
|
435
|
+
rb_define_method(bpa_class, "write_set_end", rb_thrift_binary_proto_write_set_end, 0);
|
436
|
+
|
437
|
+
rb_define_method(bpa_class, "read_message_begin", rb_thrift_binary_proto_read_message_begin, 0);
|
438
|
+
rb_define_method(bpa_class, "read_field_begin", rb_thrift_binary_proto_read_field_begin, 0);
|
439
|
+
rb_define_method(bpa_class, "read_map_begin", rb_thrift_binary_proto_read_map_begin, 0);
|
440
|
+
rb_define_method(bpa_class, "read_list_begin", rb_thrift_binary_proto_read_list_begin, 0);
|
441
|
+
rb_define_method(bpa_class, "read_set_begin", rb_thrift_binary_proto_read_set_begin, 0);
|
442
|
+
rb_define_method(bpa_class, "read_byte", rb_thrift_binary_proto_read_byte, 0);
|
443
|
+
rb_define_method(bpa_class, "read_bool", rb_thrift_binary_proto_read_bool, 0);
|
444
|
+
rb_define_method(bpa_class, "read_i16", rb_thrift_binary_proto_read_i16, 0);
|
445
|
+
rb_define_method(bpa_class, "read_i32", rb_thrift_binary_proto_read_i32, 0);
|
446
|
+
rb_define_method(bpa_class, "read_i64", rb_thrift_binary_proto_read_i64, 0);
|
447
|
+
rb_define_method(bpa_class, "read_double", rb_thrift_binary_proto_read_double, 0);
|
448
|
+
rb_define_method(bpa_class, "read_string", rb_thrift_binary_proto_read_string, 0);
|
449
|
+
rb_define_method(bpa_class, "read_binary", rb_thrift_binary_proto_read_binary, 0);
|
450
|
+
// unused methods
|
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", 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
|
+
|
459
|
+
rbuf_ivar_id = rb_intern("@rbuf");
|
460
|
+
}
|