Class: Thrift::BaseProtocol
- Inherits:
-
Object
- Object
- Thrift::BaseProtocol
show all
- Defined in:
- lib/thrift/protocol/base_protocol.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#initialize(trans) ⇒ BaseProtocol
constructor
A new instance of BaseProtocol.
-
#native? ⇒ Boolean
-
#read_binary ⇒ Object
Reads a Thrift Binary (Thrift String without encoding).
-
#read_bool ⇒ Object
-
#read_byte ⇒ Object
-
#read_double ⇒ Object
-
#read_field_begin ⇒ Object
-
#read_field_end ⇒ Object
-
#read_i16 ⇒ Object
-
#read_i32 ⇒ Object
-
#read_i64 ⇒ Object
-
#read_list_begin ⇒ Object
-
#read_list_end ⇒ Object
-
#read_map_begin ⇒ Object
-
#read_map_end ⇒ Object
-
#read_message_begin ⇒ Object
-
#read_message_end ⇒ Object
-
#read_set_begin ⇒ Object
-
#read_set_end ⇒ Object
-
#read_string ⇒ Object
-
#read_struct_begin ⇒ Object
-
#read_struct_end ⇒ Object
-
#read_type(field_info) ⇒ Object
Reads a field value based on the field information.
-
#read_uuid ⇒ Object
Reads a UUID as 16 bytes and returns it as a string.
-
#skip(type) ⇒ Object
-
#to_s ⇒ Object
-
#write_binary(buf) ⇒ Object
Writes a Thrift Binary (Thrift String with no encoding).
-
#write_bool(bool) ⇒ Object
-
#write_byte(byte) ⇒ Object
-
#write_double(dub) ⇒ Object
-
#write_field(*args) ⇒ Object
Writes a field based on the field information, field ID and value.
-
#write_field_begin(name, type, id) ⇒ Object
-
#write_field_end ⇒ Object
-
#write_field_stop ⇒ Object
-
#write_i16(i16) ⇒ Object
-
#write_i32(i32) ⇒ Object
-
#write_i64(i64) ⇒ Object
-
#write_list_begin(etype, size) ⇒ Object
-
#write_list_end ⇒ Object
-
#write_map_begin(ktype, vtype, size) ⇒ Object
-
#write_map_end ⇒ Object
-
#write_message_begin(name, type, seqid) ⇒ Object
-
#write_message_end ⇒ Object
-
#write_set_begin(etype, size) ⇒ Object
-
#write_set_end ⇒ Object
-
#write_string(str) ⇒ Object
-
#write_struct_begin(name) ⇒ Object
-
#write_struct_end ⇒ Object
-
#write_type(field_info, value) ⇒ Object
Writes a field value based on the field information.
-
#write_uuid(uuid) ⇒ Object
Writes a UUID as 16 bytes.
Constructor Details
Returns a new instance of BaseProtocol.
46
47
48
|
# File 'lib/thrift/protocol/base_protocol.rb', line 46
def initialize(trans)
@trans = trans
end
|
Instance Attribute Details
#trans ⇒ Object
Returns the value of attribute trans.
44
45
46
|
# File 'lib/thrift/protocol/base_protocol.rb', line 44
def trans
@trans
end
|
Instance Method Details
#native? ⇒ Boolean
50
51
52
53
|
# File 'lib/thrift/protocol/base_protocol.rb', line 50
def native?
puts "wrong method is being called!"
false
end
|
#read_binary ⇒ Object
Reads a Thrift Binary (Thrift String without encoding). All Strings will be returned with an Encoding of BINARY.
Returns a String.
220
221
222
|
# File 'lib/thrift/protocol/base_protocol.rb', line 220
def read_binary
raise NotImplementedError
end
|
#read_bool ⇒ Object
185
186
187
|
# File 'lib/thrift/protocol/base_protocol.rb', line 185
def read_bool
raise NotImplementedError
end
|
#read_byte ⇒ Object
189
190
191
|
# File 'lib/thrift/protocol/base_protocol.rb', line 189
def read_byte
raise NotImplementedError
end
|
#read_double ⇒ Object
205
206
207
|
# File 'lib/thrift/protocol/base_protocol.rb', line 205
def read_double
raise NotImplementedError
end
|
#read_field_begin ⇒ Object
161
162
163
|
# File 'lib/thrift/protocol/base_protocol.rb', line 161
def read_field_begin
raise NotImplementedError
end
|
#read_field_end ⇒ Object
165
|
# File 'lib/thrift/protocol/base_protocol.rb', line 165
def read_field_end; nil; end
|
#read_i16 ⇒ Object
193
194
195
|
# File 'lib/thrift/protocol/base_protocol.rb', line 193
def read_i16
raise NotImplementedError
end
|
#read_i32 ⇒ Object
197
198
199
|
# File 'lib/thrift/protocol/base_protocol.rb', line 197
def read_i32
raise NotImplementedError
end
|
#read_i64 ⇒ Object
201
202
203
|
# File 'lib/thrift/protocol/base_protocol.rb', line 201
def read_i64
raise NotImplementedError
end
|
#read_list_begin ⇒ Object
173
174
175
|
# File 'lib/thrift/protocol/base_protocol.rb', line 173
def read_list_begin
raise NotImplementedError
end
|
#read_list_end ⇒ Object
177
|
# File 'lib/thrift/protocol/base_protocol.rb', line 177
def read_list_end; nil; end
|
#read_map_begin ⇒ Object
167
168
169
|
# File 'lib/thrift/protocol/base_protocol.rb', line 167
def read_map_begin
raise NotImplementedError
end
|
#read_map_end ⇒ Object
171
|
# File 'lib/thrift/protocol/base_protocol.rb', line 171
def read_map_end; nil; end
|
#read_message_begin ⇒ Object
149
150
151
|
# File 'lib/thrift/protocol/base_protocol.rb', line 149
def read_message_begin
raise NotImplementedError
end
|
#read_message_end ⇒ Object
153
|
# File 'lib/thrift/protocol/base_protocol.rb', line 153
def read_message_end; nil; end
|
#read_set_begin ⇒ Object
179
180
181
|
# File 'lib/thrift/protocol/base_protocol.rb', line 179
def read_set_begin
raise NotImplementedError
end
|
#read_set_end ⇒ Object
183
|
# File 'lib/thrift/protocol/base_protocol.rb', line 183
def read_set_end; nil; end
|
#read_string ⇒ Object
Reads a Thrift String. All Strings will be returned with an Encoding of UTF-8.
Returns a String.
212
213
214
|
# File 'lib/thrift/protocol/base_protocol.rb', line 212
def read_string
raise NotImplementedError
end
|
#read_struct_begin ⇒ Object
155
156
157
|
# File 'lib/thrift/protocol/base_protocol.rb', line 155
def read_struct_begin
raise NotImplementedError
end
|
#read_struct_end ⇒ Object
159
|
# File 'lib/thrift/protocol/base_protocol.rb', line 159
def read_struct_end; nil; end
|
#read_type(field_info) ⇒ Object
Reads a field value based on the field information.
field_info - A Hash containing the pertinent data to write:
:type - The Thrift::Types constant that determines how the value is written.
:binary - A flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
Returns the value read; object type varies based on field_info.
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
# File 'lib/thrift/protocol/base_protocol.rb', line 311
def read_type(field_info)
if field_info.is_a? Integer
field_info = {:type => field_info}
end
case field_info[:type]
when Types::BOOL
read_bool
when Types::BYTE
read_byte
when Types::DOUBLE
read_double
when Types::I16
read_i16
when Types::I32
read_i32
when Types::I64
read_i64
when Types::STRING
if field_info[:binary]
read_binary
else
read_string
end
when Types::UUID
read_uuid
else
raise NotImplementedError
end
end
|
#read_uuid ⇒ Object
Reads a UUID as 16 bytes and returns it as a string.
Returns a String (e.g. “550e8400-e29b-41d4-a716-446655440000”).
227
228
229
|
# File 'lib/thrift/protocol/base_protocol.rb', line 227
def read_uuid
raise NotImplementedError
end
|
#skip(type) ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
# File 'lib/thrift/protocol/base_protocol.rb', line 344
def skip(type)
case type
when Types::BOOL
read_bool
when Types::BYTE
read_byte
when Types::I16
read_i16
when Types::I32
read_i32
when Types::I64
read_i64
when Types::DOUBLE
read_double
when Types::STRING
read_string
when Types::UUID
read_uuid
when Types::STRUCT
read_struct_begin
while true
name, type, id = read_field_begin
break if type == Types::STOP
skip(type)
read_field_end
end
read_struct_end
when Types::MAP
ktype, vtype, size = read_map_begin
size.times do
skip(ktype)
skip(vtype)
end
read_map_end
when Types::SET
etype, size = read_set_begin
size.times do
skip(etype)
end
read_set_end
when Types::LIST
etype, size = read_list_begin
size.times do
skip(etype)
end
read_list_end
else
raise ProtocolException.new(ProtocolException::INVALID_DATA, 'Invalid data')
end
end
|
#to_s ⇒ Object
395
396
397
|
# File 'lib/thrift/protocol/base_protocol.rb', line 395
def to_s
"#{trans.to_s}"
end
|
#write_binary(buf) ⇒ Object
Writes a Thrift Binary (Thrift String with no encoding). The String passed will forced into BINARY encoding.
buf - The String to write.
Returns nothing.
136
137
138
|
# File 'lib/thrift/protocol/base_protocol.rb', line 136
def write_binary(buf)
raise NotImplementedError
end
|
#write_bool(bool) ⇒ Object
95
96
97
|
# File 'lib/thrift/protocol/base_protocol.rb', line 95
def write_bool(bool)
raise NotImplementedError
end
|
#write_byte(byte) ⇒ Object
99
100
101
|
# File 'lib/thrift/protocol/base_protocol.rb', line 99
def write_byte(byte)
raise NotImplementedError
end
|
#write_double(dub) ⇒ Object
115
116
117
|
# File 'lib/thrift/protocol/base_protocol.rb', line 115
def write_double(dub)
raise NotImplementedError
end
|
#write_field(*args) ⇒ Object
Writes a field based on the field information, field ID and value.
field_info - A Hash containing the definition of the field:
:name - The name of the field.
:type - The type of the field, which must be a Thrift::Types constant.
:binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
fid - The ID of the field. value - The field’s value to write; object type varies based on :type.
Returns nothing.
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/thrift/protocol/base_protocol.rb', line 241
def write_field(*args)
if args.size == 3
field_info = args[0]
fid = args[1]
value = args[2]
elsif args.size == 4
field_info = {:name => args[0], :type => args[1]}
fid = args[2]
value = args[3]
else
raise ArgumentError, "wrong number of arguments (#{args.size} for 3)"
end
write_field_begin(field_info[:name], field_info[:type], fid)
write_type(field_info, value)
write_field_end
end
|
#write_field_begin(name, type, id) ⇒ Object
67
68
69
|
# File 'lib/thrift/protocol/base_protocol.rb', line 67
def write_field_begin(name, type, id)
raise NotImplementedError
end
|
#write_field_end ⇒ Object
71
|
# File 'lib/thrift/protocol/base_protocol.rb', line 71
def write_field_end; nil; end
|
#write_field_stop ⇒ Object
73
74
75
|
# File 'lib/thrift/protocol/base_protocol.rb', line 73
def write_field_stop
raise NotImplementedError
end
|
#write_i16(i16) ⇒ Object
103
104
105
|
# File 'lib/thrift/protocol/base_protocol.rb', line 103
def write_i16(i16)
raise NotImplementedError
end
|
#write_i32(i32) ⇒ Object
107
108
109
|
# File 'lib/thrift/protocol/base_protocol.rb', line 107
def write_i32(i32)
raise NotImplementedError
end
|
#write_i64(i64) ⇒ Object
111
112
113
|
# File 'lib/thrift/protocol/base_protocol.rb', line 111
def write_i64(i64)
raise NotImplementedError
end
|
#write_list_begin(etype, size) ⇒ Object
83
84
85
|
# File 'lib/thrift/protocol/base_protocol.rb', line 83
def write_list_begin(etype, size)
raise NotImplementedError
end
|
#write_list_end ⇒ Object
87
|
# File 'lib/thrift/protocol/base_protocol.rb', line 87
def write_list_end; nil; end
|
#write_map_begin(ktype, vtype, size) ⇒ Object
77
78
79
|
# File 'lib/thrift/protocol/base_protocol.rb', line 77
def write_map_begin(ktype, vtype, size)
raise NotImplementedError
end
|
#write_map_end ⇒ Object
81
|
# File 'lib/thrift/protocol/base_protocol.rb', line 81
def write_map_end; nil; end
|
#write_message_begin(name, type, seqid) ⇒ Object
55
56
57
|
# File 'lib/thrift/protocol/base_protocol.rb', line 55
def write_message_begin(name, type, seqid)
raise NotImplementedError
end
|
#write_message_end ⇒ Object
59
|
# File 'lib/thrift/protocol/base_protocol.rb', line 59
def write_message_end; nil; end
|
#write_set_begin(etype, size) ⇒ Object
89
90
91
|
# File 'lib/thrift/protocol/base_protocol.rb', line 89
def write_set_begin(etype, size)
raise NotImplementedError
end
|
#write_set_end ⇒ Object
93
|
# File 'lib/thrift/protocol/base_protocol.rb', line 93
def write_set_end; nil; end
|
#write_string(str) ⇒ Object
Writes a Thrift String. The String passed will be transcoded to UTF-8.
str - The String to write.
Raises EncodingError if the transcoding to UTF-8 fails.
Returns nothing.
126
127
128
|
# File 'lib/thrift/protocol/base_protocol.rb', line 126
def write_string(str)
raise NotImplementedError
end
|
#write_struct_begin(name) ⇒ Object
61
62
63
|
# File 'lib/thrift/protocol/base_protocol.rb', line 61
def write_struct_begin(name)
raise NotImplementedError
end
|
#write_struct_end ⇒ Object
65
|
# File 'lib/thrift/protocol/base_protocol.rb', line 65
def write_struct_end; nil; end
|
#write_type(field_info, value) ⇒ Object
Writes a field value based on the field information.
field_info - A Hash containing the definition of the field:
:type - The Thrift::Types constant that determines how the value is written.
:binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
value - The field’s value to write; object type varies based on field_info.
Returns nothing.
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/thrift/protocol/base_protocol.rb', line 269
def write_type(field_info, value)
if field_info.is_a? Integer
field_info = {:type => field_info}
end
case field_info[:type]
when Types::BOOL
write_bool(value)
when Types::BYTE
write_byte(value)
when Types::DOUBLE
write_double(value)
when Types::I16
write_i16(value)
when Types::I32
write_i32(value)
when Types::I64
write_i64(value)
when Types::STRING
if field_info[:binary]
write_binary(value)
else
write_string(value)
end
when Types::UUID
write_uuid(value)
when Types::STRUCT
value.write(self)
else
raise NotImplementedError
end
end
|
#write_uuid(uuid) ⇒ Object
Writes a UUID as 16 bytes.
uuid - The UUID string to write (e.g. “550e8400-e29b-41d4-a716-446655440000”).
Returns nothing.
145
146
147
|
# File 'lib/thrift/protocol/base_protocol.rb', line 145
def write_uuid(uuid)
raise NotImplementedError
end
|