class Thrift::BaseProtocol

Attributes

trans[R]

Public Class Methods

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

Public Instance Methods

native?() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 50
def native?
  puts "wrong method is being called!"
  false
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, line 211
def read_binary
  raise NotImplementedError
end
read_bool() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 176
def read_bool
  raise NotImplementedError
end
read_byte() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 180
def read_byte
  raise NotImplementedError
end
read_double() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 196
def read_double
  raise NotImplementedError
end
read_field_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 152
def read_field_begin
  raise NotImplementedError
end
read_field_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 156
def read_field_end; nil; end
read_i16() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 184
def read_i16
  raise NotImplementedError
end
read_i32() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 188
def read_i32
  raise NotImplementedError
end
read_i64() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 192
def read_i64
  raise NotImplementedError
end
read_list_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 164
def read_list_begin
  raise NotImplementedError
end
read_list_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 168
def read_list_end; nil; end
read_map_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 158
def read_map_begin
  raise NotImplementedError
end
read_map_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 162
def read_map_end; nil; end
read_message_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 140
def read_message_begin
  raise NotImplementedError
end
read_message_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 144
def read_message_end; nil; end
read_set_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 170
def read_set_begin
  raise NotImplementedError
end
read_set_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 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, line 203
def read_string
  raise NotImplementedError
end
read_struct_begin() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 146
def read_struct_begin
  raise NotImplementedError
end
read_struct_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 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, line 293
def read_type(field_info)
  # if field_info is a Fixnum, assume it is a Thrift::Types constant
  # convert it into a field_info Hash for backwards compatibility
  if field_info.is_a? Fixnum
    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
  else
    raise NotImplementedError
  end
end
skip(type) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 324
def skip(type)
  case type
  when Types::STOP
    nil
  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::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
  end
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, line 136
def write_binary(buf)
  raise NotImplementedError
end
write_bool(bool) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 95
def write_bool(bool)
  raise NotImplementedError
end
write_byte(byte) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 99
def write_byte(byte)
  raise NotImplementedError
end
write_double(dub) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 115
def write_double(dub)
  raise NotImplementedError
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, line 225
def write_field(*args)
  if args.size == 3
    # handles the documented method signature - write_field(field_info, fid, value)
    field_info = args[0]
    fid = args[1]
    value = args[2]
  elsif args.size == 4
    # handles the deprecated method signature - write_field(name, type, fid, value)
    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) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 67
def write_field_begin(name, type, id)
  raise NotImplementedError
end
write_field_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 71
def write_field_end; nil; end
write_field_stop() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 73
def write_field_stop
  raise NotImplementedError
end
write_i16(i16) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 103
def write_i16(i16)
  raise NotImplementedError
end
write_i32(i32) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 107
def write_i32(i32)
  raise NotImplementedError
end
write_i64(i64) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 111
def write_i64(i64)
  raise NotImplementedError
end
write_list_begin(etype, size) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 83
def write_list_begin(etype, size)
  raise NotImplementedError
end
write_list_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 87
def write_list_end; nil; end
write_map_begin(ktype, vtype, size) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 77
def write_map_begin(ktype, vtype, size)
  raise NotImplementedError
end
write_map_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 81
def write_map_end; nil; end
write_message_begin(name, type, seqid) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 55
def write_message_begin(name, type, seqid)
  raise NotImplementedError
end
write_message_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 59
def write_message_end; nil; end
write_set_begin(etype, size) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 89
def write_set_begin(etype, size)
  raise NotImplementedError
end
write_set_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 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, line 126
def write_string(str)
  raise NotImplementedError
end
write_struct_begin(name) click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 61
def write_struct_begin(name)
  raise NotImplementedError
end
write_struct_end() click to toggle source
# File lib/thrift/protocol/base_protocol.rb, line 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, line 253
def write_type(field_info, value)
  # if field_info is a Fixnum, assume it is a Thrift::Types constant
  # convert it into a field_info Hash for backwards compatibility
  if field_info.is_a? Fixnum
    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::STRUCT
    value.write(self)
  else
    raise NotImplementedError
  end
end