class Thrift::BaseProtocol
Attributes
Public Class Methods
# File lib/thrift/protocol/base_protocol.rb 46 def initialize(trans) 47 @trans = trans 48 end
Public Instance Methods
# File lib/thrift/protocol/base_protocol.rb 50 def native? 51 puts "wrong method is being called!" 52 false 53 end
# File lib/thrift/protocol/base_protocol.rb 176 def read_bool 177 raise NotImplementedError 178 end
# File lib/thrift/protocol/base_protocol.rb 180 def read_byte 181 raise NotImplementedError 182 end
# File lib/thrift/protocol/base_protocol.rb 196 def read_double 197 raise NotImplementedError 198 end
# File lib/thrift/protocol/base_protocol.rb 152 def read_field_begin 153 raise NotImplementedError 154 end
# File lib/thrift/protocol/base_protocol.rb 156 def read_field_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 184 def read_i16 185 raise NotImplementedError 186 end
# File lib/thrift/protocol/base_protocol.rb 188 def read_i32 189 raise NotImplementedError 190 end
# File lib/thrift/protocol/base_protocol.rb 192 def read_i64 193 raise NotImplementedError 194 end
# File lib/thrift/protocol/base_protocol.rb 164 def read_list_begin 165 raise NotImplementedError 166 end
# File lib/thrift/protocol/base_protocol.rb 168 def read_list_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 158 def read_map_begin 159 raise NotImplementedError 160 end
# File lib/thrift/protocol/base_protocol.rb 162 def read_map_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 140 def read_message_begin 141 raise NotImplementedError 142 end
# File lib/thrift/protocol/base_protocol.rb 144 def read_message_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 170 def read_set_begin 171 raise NotImplementedError 172 end
# File lib/thrift/protocol/base_protocol.rb 174 def read_set_end; nil; end
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
# File lib/thrift/protocol/base_protocol.rb 146 def read_struct_begin 147 raise NotImplementedError 148 end
# File lib/thrift/protocol/base_protocol.rb 150 def read_struct_end; nil; end
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
# File lib/thrift/protocol/base_protocol.rb 324 def skip(type) 325 case type 326 when Types::BOOL 327 read_bool 328 when Types::BYTE 329 read_byte 330 when Types::I16 331 read_i16 332 when Types::I32 333 read_i32 334 when Types::I64 335 read_i64 336 when Types::DOUBLE 337 read_double 338 when Types::STRING 339 read_string 340 when Types::STRUCT 341 read_struct_begin 342 while true 343 name, type, id = read_field_begin 344 break if type == Types::STOP 345 skip(type) 346 read_field_end 347 end 348 read_struct_end 349 when Types::MAP 350 ktype, vtype, size = read_map_begin 351 size.times do 352 skip(ktype) 353 skip(vtype) 354 end 355 read_map_end 356 when Types::SET 357 etype, size = read_set_begin 358 size.times do 359 skip(etype) 360 end 361 read_set_end 362 when Types::LIST 363 etype, size = read_list_begin 364 size.times do 365 skip(etype) 366 end 367 read_list_end 368 else 369 raise ProtocolException.new(ProtocolException::INVALID_DATA, 'Invalid data') 370 end 371 end
# File lib/thrift/protocol/base_protocol.rb 373 def to_s 374 "#{trans.to_s}" 375 end
# File lib/thrift/protocol/base_protocol.rb 95 def write_bool(bool) 96 raise NotImplementedError 97 end
# File lib/thrift/protocol/base_protocol.rb 99 def write_byte(byte) 100 raise NotImplementedError 101 end
# File lib/thrift/protocol/base_protocol.rb 115 def write_double(dub) 116 raise NotImplementedError 117 end
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
# File lib/thrift/protocol/base_protocol.rb 67 def write_field_begin(name, type, id) 68 raise NotImplementedError 69 end
# File lib/thrift/protocol/base_protocol.rb 71 def write_field_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 73 def write_field_stop 74 raise NotImplementedError 75 end
# File lib/thrift/protocol/base_protocol.rb 103 def write_i16(i16) 104 raise NotImplementedError 105 end
# File lib/thrift/protocol/base_protocol.rb 107 def write_i32(i32) 108 raise NotImplementedError 109 end
# File lib/thrift/protocol/base_protocol.rb 111 def write_i64(i64) 112 raise NotImplementedError 113 end
# File lib/thrift/protocol/base_protocol.rb 83 def write_list_begin(etype, size) 84 raise NotImplementedError 85 end
# File lib/thrift/protocol/base_protocol.rb 87 def write_list_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 77 def write_map_begin(ktype, vtype, size) 78 raise NotImplementedError 79 end
# File lib/thrift/protocol/base_protocol.rb 81 def write_map_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 55 def write_message_begin(name, type, seqid) 56 raise NotImplementedError 57 end
# File lib/thrift/protocol/base_protocol.rb 59 def write_message_end; nil; end
# File lib/thrift/protocol/base_protocol.rb 89 def write_set_begin(etype, size) 90 raise NotImplementedError 91 end
# File lib/thrift/protocol/base_protocol.rb 93 def write_set_end; nil; end
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
# File lib/thrift/protocol/base_protocol.rb 61 def write_struct_begin(name) 62 raise NotImplementedError 63 end
# File lib/thrift/protocol/base_protocol.rb 65 def write_struct_end; nil; end
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