thrift 0.0.751142 → 0.0.810255.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -1
- data/Manifest +47 -44
- data/README +19 -6
- data/Rakefile +1 -1
- data/benchmark/Benchmark.thrift +19 -0
- data/benchmark/benchmark.rb +20 -3
- data/benchmark/client.rb +20 -2
- data/benchmark/server.rb +22 -4
- data/benchmark/thin_server.rb +22 -4
- data/ext/binary_protocol_accelerated.c +32 -21
- data/ext/binary_protocol_accelerated.h +19 -0
- data/ext/compact_protocol.c +665 -0
- data/ext/compact_protocol.h +20 -0
- data/ext/constants.h +19 -1
- data/ext/extconf.rb +19 -0
- data/ext/macros.h +41 -0
- data/ext/memory_buffer.c +29 -5
- data/ext/memory_buffer.h +19 -0
- data/ext/protocol.c +20 -1
- data/ext/protocol.h +19 -0
- data/ext/struct.c +115 -83
- data/ext/struct.h +19 -0
- data/ext/thrift_native.c +23 -2
- data/lib/thrift/client.rb +19 -1
- data/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/thrift/core_ext.rb +23 -0
- data/lib/thrift/exceptions.rb +19 -2
- data/lib/thrift/processor.rb +19 -1
- data/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
- data/lib/thrift/protocol/compact_protocol.rb +422 -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/{httpserver.rb → mongrel_http_server.rb} +19 -5
- data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
- 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 +73 -47
- 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 +70 -0
- data/lib/thrift/transport/buffered_transport.rb +77 -0
- data/lib/thrift/transport/framed_transport.rb +90 -0
- data/lib/thrift/transport/http_client_transport.rb +45 -0
- data/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/thrift/transport/socket.rb +22 -53
- data/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/thrift/types.rb +20 -2
- data/lib/thrift.rb +50 -19
- data/script/proto_benchmark.rb +121 -0
- data/script/read_struct.rb +43 -0
- data/script/write_struct.rb +30 -0
- data/spec/ThriftSpec.thrift +40 -2
- data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
- data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
- data/spec/binary_protocol_accelerated_spec.rb +41 -0
- data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
- data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
- data/spec/client_spec.rb +23 -4
- data/spec/compact_protocol_spec.rb +117 -0
- data/spec/exception_spec.rb +19 -0
- data/spec/http_client_spec.rb +49 -0
- data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
- data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
- data/spec/processor_spec.rb +19 -0
- data/spec/serializer_spec.rb +27 -10
- data/spec/server_socket_spec.rb +80 -0
- data/spec/server_spec.rb +35 -16
- data/spec/socket_spec.rb +19 -55
- data/spec/socket_spec_shared.rb +19 -0
- data/spec/spec_helper.rb +34 -9
- data/spec/struct_spec.rb +26 -18
- data/spec/types_spec.rb +19 -1
- data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
- data/thrift.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +80 -70
- metadata.gz.sig +0 -0
- data/COPYING +0 -14
- data/LICENSE +0 -14
- data/Makefile.am +0 -15
- data/benchmark/gen-rb/BenchmarkService.rb +0 -81
- data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/Benchmark_types.rb +0 -10
- data/lib/thrift/deprecation.rb +0 -155
- data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
- data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
- data/lib/thrift/protocol/tprotocol.rb +0 -2
- data/lib/thrift/protocol.rb +0 -270
- data/lib/thrift/serializer.rb +0 -27
- data/lib/thrift/server/thttpserver.rb +0 -2
- data/lib/thrift/server/tserver.rb +0 -2
- data/lib/thrift/server.rb +0 -135
- data/lib/thrift/thrift.rb +0 -14
- data/lib/thrift/transport/httpclient.rb +0 -29
- data/lib/thrift/transport/thttpclient.rb +0 -2
- data/lib/thrift/transport/tsocket.rb +0 -2
- data/lib/thrift/transport/ttransport.rb +0 -2
- data/lib/thrift/transport/unixsocket.rb +0 -58
- data/lib/thrift/transport.rb +0 -319
- data/spec/backwards_compatibility_spec.rb +0 -136
- data/spec/binaryprotocolaccelerated_spec.rb +0 -101
- data/spec/deprecation_spec.rb +0 -443
- data/spec/gen-rb/NonblockingService.rb +0 -268
- data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
- data/spec/gen-rb/ThriftSpec_types.rb +0 -134
- data/spec/httpclient_spec.rb +0 -31
data/lib/thrift/client.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
module Thrift
|
2
21
|
module Client
|
3
22
|
def initialize(iprot, oprot=nil)
|
@@ -40,5 +59,4 @@ module Thrift
|
|
40
59
|
end
|
41
60
|
end
|
42
61
|
end
|
43
|
-
deprecate_module! :ThriftClient => Client
|
44
62
|
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
# Versions of ruby pre 1.8.7 do not have an .ord method available in the Fixnum
|
21
|
+
# class.
|
22
|
+
#
|
23
|
+
if RUBY_VERSION < "1.8.7"
|
24
|
+
class Fixnum
|
25
|
+
def ord
|
26
|
+
self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each do |file|
|
21
|
+
name = File.basename(file, '.rb')
|
22
|
+
require "thrift/core_ext/#{name}"
|
23
|
+
end
|
data/lib/thrift/exceptions.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
module Thrift
|
2
21
|
class Exception < StandardError
|
3
22
|
def initialize(message)
|
@@ -7,7 +26,6 @@ module Thrift
|
|
7
26
|
|
8
27
|
attr_reader :message
|
9
28
|
end
|
10
|
-
deprecate_class! :TException => Exception
|
11
29
|
|
12
30
|
class ApplicationException < Exception
|
13
31
|
|
@@ -61,5 +79,4 @@ module Thrift
|
|
61
79
|
end
|
62
80
|
|
63
81
|
end
|
64
|
-
deprecate_class! :TApplicationException => ApplicationException
|
65
82
|
end
|
data/lib/thrift/processor.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
module Thrift
|
2
21
|
module Processor
|
3
22
|
def initialize(handler)
|
@@ -35,5 +54,4 @@ module Thrift
|
|
35
54
|
oprot.trans.flush
|
36
55
|
end
|
37
56
|
end
|
38
|
-
deprecate_module! :TProcessor => Processor
|
39
57
|
end
|
@@ -0,0 +1,290 @@
|
|
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
|
+
# this require is to make generated struct definitions happy
|
21
|
+
require 'set'
|
22
|
+
|
23
|
+
module Thrift
|
24
|
+
class ProtocolException < Exception
|
25
|
+
|
26
|
+
UNKNOWN = 0
|
27
|
+
INVALID_DATA = 1
|
28
|
+
NEGATIVE_SIZE = 2
|
29
|
+
SIZE_LIMIT = 3
|
30
|
+
BAD_VERSION = 4
|
31
|
+
|
32
|
+
attr_reader :type
|
33
|
+
|
34
|
+
def initialize(type=UNKNOWN, message=nil)
|
35
|
+
super(message)
|
36
|
+
@type = type
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class BaseProtocol
|
41
|
+
|
42
|
+
attr_reader :trans
|
43
|
+
|
44
|
+
def initialize(trans)
|
45
|
+
@trans = trans
|
46
|
+
end
|
47
|
+
|
48
|
+
def native?
|
49
|
+
puts "wrong method is being called!"
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_message_begin(name, type, seqid)
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_message_end; nil; end
|
58
|
+
|
59
|
+
def write_struct_begin(name)
|
60
|
+
raise NotImplementedError
|
61
|
+
end
|
62
|
+
|
63
|
+
def write_struct_end; nil; end
|
64
|
+
|
65
|
+
def write_field_begin(name, type, id)
|
66
|
+
raise NotImplementedError
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_field_end; nil; end
|
70
|
+
|
71
|
+
def write_field_stop
|
72
|
+
raise NotImplementedError
|
73
|
+
end
|
74
|
+
|
75
|
+
def write_map_begin(ktype, vtype, size)
|
76
|
+
raise NotImplementedError
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_map_end; nil; end
|
80
|
+
|
81
|
+
def write_list_begin(etype, size)
|
82
|
+
raise NotImplementedError
|
83
|
+
end
|
84
|
+
|
85
|
+
def write_list_end; nil; end
|
86
|
+
|
87
|
+
def write_set_begin(etype, size)
|
88
|
+
raise NotImplementedError
|
89
|
+
end
|
90
|
+
|
91
|
+
def write_set_end; nil; end
|
92
|
+
|
93
|
+
def write_bool(bool)
|
94
|
+
raise NotImplementedError
|
95
|
+
end
|
96
|
+
|
97
|
+
def write_byte(byte)
|
98
|
+
raise NotImplementedError
|
99
|
+
end
|
100
|
+
|
101
|
+
def write_i16(i16)
|
102
|
+
raise NotImplementedError
|
103
|
+
end
|
104
|
+
|
105
|
+
def write_i32(i32)
|
106
|
+
raise NotImplementedError
|
107
|
+
end
|
108
|
+
|
109
|
+
def write_i64(i64)
|
110
|
+
raise NotImplementedError
|
111
|
+
end
|
112
|
+
|
113
|
+
def write_double(dub)
|
114
|
+
raise NotImplementedError
|
115
|
+
end
|
116
|
+
|
117
|
+
def write_string(str)
|
118
|
+
raise NotImplementedError
|
119
|
+
end
|
120
|
+
|
121
|
+
def read_message_begin
|
122
|
+
raise NotImplementedError
|
123
|
+
end
|
124
|
+
|
125
|
+
def read_message_end; nil; end
|
126
|
+
|
127
|
+
def read_struct_begin
|
128
|
+
raise NotImplementedError
|
129
|
+
end
|
130
|
+
|
131
|
+
def read_struct_end; nil; end
|
132
|
+
|
133
|
+
def read_field_begin
|
134
|
+
raise NotImplementedError
|
135
|
+
end
|
136
|
+
|
137
|
+
def read_field_end; nil; end
|
138
|
+
|
139
|
+
def read_map_begin
|
140
|
+
raise NotImplementedError
|
141
|
+
end
|
142
|
+
|
143
|
+
def read_map_end; nil; end
|
144
|
+
|
145
|
+
def read_list_begin
|
146
|
+
raise NotImplementedError
|
147
|
+
end
|
148
|
+
|
149
|
+
def read_list_end; nil; end
|
150
|
+
|
151
|
+
def read_set_begin
|
152
|
+
raise NotImplementedError
|
153
|
+
end
|
154
|
+
|
155
|
+
def read_set_end; nil; end
|
156
|
+
|
157
|
+
def read_bool
|
158
|
+
raise NotImplementedError
|
159
|
+
end
|
160
|
+
|
161
|
+
def read_byte
|
162
|
+
raise NotImplementedError
|
163
|
+
end
|
164
|
+
|
165
|
+
def read_i16
|
166
|
+
raise NotImplementedError
|
167
|
+
end
|
168
|
+
|
169
|
+
def read_i32
|
170
|
+
raise NotImplementedError
|
171
|
+
end
|
172
|
+
|
173
|
+
def read_i64
|
174
|
+
raise NotImplementedError
|
175
|
+
end
|
176
|
+
|
177
|
+
def read_double
|
178
|
+
raise NotImplementedError
|
179
|
+
end
|
180
|
+
|
181
|
+
def read_string
|
182
|
+
raise NotImplementedError
|
183
|
+
end
|
184
|
+
|
185
|
+
def write_field(name, type, fid, value)
|
186
|
+
write_field_begin(name, type, fid)
|
187
|
+
write_type(type, value)
|
188
|
+
write_field_end
|
189
|
+
end
|
190
|
+
|
191
|
+
def write_type(type, value)
|
192
|
+
case type
|
193
|
+
when Types::BOOL
|
194
|
+
write_bool(value)
|
195
|
+
when Types::BYTE
|
196
|
+
write_byte(value)
|
197
|
+
when Types::DOUBLE
|
198
|
+
write_double(value)
|
199
|
+
when Types::I16
|
200
|
+
write_i16(value)
|
201
|
+
when Types::I32
|
202
|
+
write_i32(value)
|
203
|
+
when Types::I64
|
204
|
+
write_i64(value)
|
205
|
+
when Types::STRING
|
206
|
+
write_string(value)
|
207
|
+
when Types::STRUCT
|
208
|
+
value.write(self)
|
209
|
+
else
|
210
|
+
raise NotImplementedError
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def read_type(type)
|
215
|
+
case type
|
216
|
+
when Types::BOOL
|
217
|
+
read_bool
|
218
|
+
when Types::BYTE
|
219
|
+
read_byte
|
220
|
+
when Types::DOUBLE
|
221
|
+
read_double
|
222
|
+
when Types::I16
|
223
|
+
read_i16
|
224
|
+
when Types::I32
|
225
|
+
read_i32
|
226
|
+
when Types::I64
|
227
|
+
read_i64
|
228
|
+
when Types::STRING
|
229
|
+
read_string
|
230
|
+
else
|
231
|
+
raise NotImplementedError
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def skip(type)
|
236
|
+
case type
|
237
|
+
when Types::STOP
|
238
|
+
nil
|
239
|
+
when Types::BOOL
|
240
|
+
read_bool
|
241
|
+
when Types::BYTE
|
242
|
+
read_byte
|
243
|
+
when Types::I16
|
244
|
+
read_i16
|
245
|
+
when Types::I32
|
246
|
+
read_i32
|
247
|
+
when Types::I64
|
248
|
+
read_i64
|
249
|
+
when Types::DOUBLE
|
250
|
+
read_double
|
251
|
+
when Types::STRING
|
252
|
+
read_string
|
253
|
+
when Types::STRUCT
|
254
|
+
read_struct_begin
|
255
|
+
while true
|
256
|
+
name, type, id = read_field_begin
|
257
|
+
break if type == Types::STOP
|
258
|
+
skip(type)
|
259
|
+
read_field_end
|
260
|
+
end
|
261
|
+
read_struct_end
|
262
|
+
when Types::MAP
|
263
|
+
ktype, vtype, size = read_map_begin
|
264
|
+
size.times do
|
265
|
+
skip(ktype)
|
266
|
+
skip(vtype)
|
267
|
+
end
|
268
|
+
read_map_end
|
269
|
+
when Types::SET
|
270
|
+
etype, size = read_set_begin
|
271
|
+
size.times do
|
272
|
+
skip(etype)
|
273
|
+
end
|
274
|
+
read_set_end
|
275
|
+
when Types::LIST
|
276
|
+
etype, size = read_list_begin
|
277
|
+
size.times do
|
278
|
+
skip(etype)
|
279
|
+
end
|
280
|
+
read_list_end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
class BaseProtocolFactory
|
286
|
+
def get_protocol(trans)
|
287
|
+
raise NotImplementedError
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
@@ -1,16 +1,24 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
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
|
+
#
|
11
19
|
|
12
20
|
module Thrift
|
13
|
-
class BinaryProtocol <
|
21
|
+
class BinaryProtocol < BaseProtocol
|
14
22
|
VERSION_MASK = 0xffff0000
|
15
23
|
VERSION_1 = 0x80010000
|
16
24
|
TYPE_MASK = 0x000000ff
|
@@ -38,6 +46,8 @@ module Thrift
|
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
49
|
+
def write_struct_begin(name); nil; end
|
50
|
+
|
41
51
|
def write_field_begin(name, type, id)
|
42
52
|
write_byte(type)
|
43
53
|
write_i16(id)
|
@@ -68,6 +78,7 @@ module Thrift
|
|
68
78
|
end
|
69
79
|
|
70
80
|
def write_byte(byte)
|
81
|
+
raise RangeError if byte < -2**31 || byte >= 2**32
|
71
82
|
trans.write([byte].pack('c'))
|
72
83
|
end
|
73
84
|
|
@@ -81,6 +92,7 @@ module Thrift
|
|
81
92
|
end
|
82
93
|
|
83
94
|
def write_i64(i64)
|
95
|
+
raise RangeError if i64 < -2**63 || i64 >= 2**64
|
84
96
|
hi = i64 >> 32
|
85
97
|
lo = i64 & 0xffffffff
|
86
98
|
trans.write([hi, lo].pack('N2'))
|
@@ -116,6 +128,8 @@ module Thrift
|
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
131
|
+
def read_struct_begin; nil; end
|
132
|
+
|
119
133
|
def read_field_begin
|
120
134
|
type = read_byte
|
121
135
|
if (type == Types::STOP)
|
@@ -152,7 +166,7 @@ module Thrift
|
|
152
166
|
|
153
167
|
def read_byte
|
154
168
|
dat = trans.read_all(1)
|
155
|
-
val = dat[0]
|
169
|
+
val = dat[0].ord
|
156
170
|
if (val > 0x7f)
|
157
171
|
val = 0 - ((val - 1) ^ 0xff)
|
158
172
|
end
|
@@ -202,12 +216,10 @@ module Thrift
|
|
202
216
|
end
|
203
217
|
|
204
218
|
end
|
205
|
-
deprecate_class! :TBinaryProtocol => BinaryProtocol
|
206
219
|
|
207
|
-
class BinaryProtocolFactory <
|
220
|
+
class BinaryProtocolFactory < BaseProtocolFactory
|
208
221
|
def get_protocol(trans)
|
209
222
|
return Thrift::BinaryProtocol.new(trans)
|
210
223
|
end
|
211
224
|
end
|
212
|
-
deprecate_class! :TBinaryProtocolFactory => BinaryProtocolFactory
|
213
225
|
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
=begin
|
21
|
+
The only change required for a transport to support BinaryProtocolAccelerated is to implement 2 methods:
|
22
|
+
* borrow(size), which takes an optional argument and returns atleast _size_ bytes from the transport,
|
23
|
+
or the default buffer size if no argument is given
|
24
|
+
* consume!(size), which removes size bytes from the front of the buffer
|
25
|
+
|
26
|
+
See MemoryBuffer and BufferedTransport for examples.
|
27
|
+
=end
|
28
|
+
|
29
|
+
module Thrift
|
30
|
+
class BinaryProtocolAcceleratedFactory < BaseProtocolFactory
|
31
|
+
def get_protocol(trans)
|
32
|
+
BinaryProtocolAccelerated.new(trans)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|