class Thrift::BaseProtocol

Attributes

trans[R]

Public Class Methods

new(trans) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
46 def initialize(trans)
47   @trans = trans
48 end

Public Instance Methods

native?() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
50 def native?
51   puts "wrong method is being called!"
52   false
53 end
read_binary() click to toggle source

Reads a Thrift Binary (Thrift String without encoding). In Ruby 1.9+, all Strings will be returned with an Encoding of BINARY.

Returns a String.

    # File lib/thrift/protocol/base_protocol.rb
211 def read_binary
212   raise NotImplementedError
213 end
read_bool() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
176 def read_bool
177   raise NotImplementedError
178 end
read_byte() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
180 def read_byte
181   raise NotImplementedError
182 end
read_double() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
196 def read_double
197   raise NotImplementedError
198 end
read_field_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
152 def read_field_begin
153   raise NotImplementedError
154 end
read_field_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
156 def read_field_end; nil; end
read_i16() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
184 def read_i16
185   raise NotImplementedError
186 end
read_i32() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
188 def read_i32
189   raise NotImplementedError
190 end
read_i64() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
192 def read_i64
193   raise NotImplementedError
194 end
read_list_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
164 def read_list_begin
165   raise NotImplementedError
166 end
read_list_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
168 def read_list_end; nil; end
read_map_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
158 def read_map_begin
159   raise NotImplementedError
160 end
read_map_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
162 def read_map_end; nil; end
read_message_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
140 def read_message_begin
141   raise NotImplementedError
142 end
read_message_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
144 def read_message_end; nil; end
read_set_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
170 def read_set_begin
171   raise NotImplementedError
172 end
read_set_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
174 def read_set_end; nil; end
read_string() click to toggle source

Reads a Thrift String. In Ruby 1.9+, all Strings will be returned with an Encoding of UTF-8.

Returns a String.

    # File lib/thrift/protocol/base_protocol.rb
203 def read_string
204   raise NotImplementedError
205 end
read_struct_begin() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
146 def read_struct_begin
147   raise NotImplementedError
148 end
read_struct_end() click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
150 def read_struct_end; nil; end
read_type(field_info) click to toggle source

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.

    # File lib/thrift/protocol/base_protocol.rb
293 def read_type(field_info)
294   # if field_info is a Fixnum, assume it is a Thrift::Types constant
295   # convert it into a field_info Hash for backwards compatibility
296   if field_info.is_a? Fixnum
297     field_info = {:type => field_info}
298   end
299 
300   case field_info[:type]
301   when Types::BOOL
302     read_bool
303   when Types::BYTE
304     read_byte
305   when Types::DOUBLE
306     read_double
307   when Types::I16
308     read_i16
309   when Types::I32
310     read_i32
311   when Types::I64
312     read_i64
313   when Types::STRING
314     if field_info[:binary]
315       read_binary
316     else
317       read_string
318     end
319   else
320     raise NotImplementedError
321   end
322 end
skip(type) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
324 def skip(type)
325   case type
326   when Types::STOP
327     nil
328   when Types::BOOL
329     read_bool
330   when Types::BYTE
331     read_byte
332   when Types::I16
333     read_i16
334   when Types::I32
335     read_i32
336   when Types::I64
337     read_i64
338   when Types::DOUBLE
339     read_double
340   when Types::STRING
341     read_string
342   when Types::STRUCT
343     read_struct_begin
344     while true
345       name, type, id = read_field_begin
346       break if type == Types::STOP
347       skip(type)
348       read_field_end
349     end
350     read_struct_end
351   when Types::MAP
352     ktype, vtype, size = read_map_begin
353     size.times do
354       skip(ktype)
355       skip(vtype)
356     end
357     read_map_end
358   when Types::SET
359     etype, size = read_set_begin
360     size.times do
361       skip(etype)
362     end
363     read_set_end
364   when Types::LIST
365     etype, size = read_list_begin
366     size.times do
367       skip(etype)
368     end
369     read_list_end
370   end
371 end
write_binary(buf) click to toggle source

Writes a Thrift Binary (Thrift String with no encoding). In Ruby 1.9+, the String passed will forced into BINARY encoding.

buf - The String to write.

Returns nothing.

    # File lib/thrift/protocol/base_protocol.rb
136 def write_binary(buf)
137   raise NotImplementedError
138 end
write_bool(bool) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
95 def write_bool(bool)
96   raise NotImplementedError
97 end
write_byte(byte) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
 99 def write_byte(byte)
100   raise NotImplementedError
101 end
write_double(dub) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
115 def write_double(dub)
116   raise NotImplementedError
117 end
write_field(*args) click to toggle source

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.

    # File lib/thrift/protocol/base_protocol.rb
225 def write_field(*args)
226   if args.size == 3
227     # handles the documented method signature - write_field(field_info, fid, value)
228     field_info = args[0]
229     fid = args[1]
230     value = args[2]
231   elsif args.size == 4
232     # handles the deprecated method signature - write_field(name, type, fid, value)
233     field_info = {:name => args[0], :type => args[1]}
234     fid = args[2]
235     value = args[3]
236   else
237     raise ArgumentError, "wrong number of arguments (#{args.size} for 3)"
238   end
239 
240   write_field_begin(field_info[:name], field_info[:type], fid)
241   write_type(field_info, value)
242   write_field_end
243 end
write_field_begin(name, type, id) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
67 def write_field_begin(name, type, id)
68   raise NotImplementedError
69 end
write_field_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
71 def write_field_end; nil; end
write_field_stop() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
73 def write_field_stop
74   raise NotImplementedError
75 end
write_i16(i16) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
103 def write_i16(i16)
104   raise NotImplementedError
105 end
write_i32(i32) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
107 def write_i32(i32)
108   raise NotImplementedError
109 end
write_i64(i64) click to toggle source
    # File lib/thrift/protocol/base_protocol.rb
111 def write_i64(i64)
112   raise NotImplementedError
113 end
write_list_begin(etype, size) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
83 def write_list_begin(etype, size)
84   raise NotImplementedError
85 end
write_list_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
87 def write_list_end; nil; end
write_map_begin(ktype, vtype, size) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
77 def write_map_begin(ktype, vtype, size)
78   raise NotImplementedError
79 end
write_map_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
81 def write_map_end; nil; end
write_message_begin(name, type, seqid) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
55 def write_message_begin(name, type, seqid)
56   raise NotImplementedError
57 end
write_message_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
59 def write_message_end; nil; end
write_set_begin(etype, size) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
89 def write_set_begin(etype, size)
90   raise NotImplementedError
91 end
write_set_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
93 def write_set_end; nil; end
write_string(str) click to toggle source

Writes a Thrift String. In Ruby 1.9+, 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.

    # File lib/thrift/protocol/base_protocol.rb
126 def write_string(str)
127   raise NotImplementedError
128 end
write_struct_begin(name) click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
61 def write_struct_begin(name)
62   raise NotImplementedError
63 end
write_struct_end() click to toggle source
   # File lib/thrift/protocol/base_protocol.rb
65 def write_struct_end; nil; end
write_type(field_info, value) click to toggle source

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.

    # File lib/thrift/protocol/base_protocol.rb
253 def write_type(field_info, value)
254   # if field_info is a Fixnum, assume it is a Thrift::Types constant
255   # convert it into a field_info Hash for backwards compatibility
256   if field_info.is_a? Fixnum
257     field_info = {:type => field_info}
258   end
259 
260   case field_info[:type]
261   when Types::BOOL
262     write_bool(value)
263   when Types::BYTE
264     write_byte(value)
265   when Types::DOUBLE
266     write_double(value)
267   when Types::I16
268     write_i16(value)
269   when Types::I32
270     write_i32(value)
271   when Types::I64
272     write_i64(value)
273   when Types::STRING
274     if field_info[:binary]
275       write_binary(value)
276     else
277       write_string(value)
278     end
279   when Types::STRUCT
280     value.write(self)
281   else
282     raise NotImplementedError
283   end
284 end