Parent

Files

Class/Module Index [+]

Quicksearch

Tarantool::Response

Constants

UTF8

Public Instance Methods

call(data) click to toggle source
# File lib/tarantool/response.rb, line 26
def call(data)
  if Exception === data
    cb.call(data)
  else
    if (ret = return_code(data)) == 0
      call_callback parse_response(data)
    else
      data.gsub!("\x00", "")
      cb.call CODE_TO_EXCEPTION[ret].new(ret, data)
    end
  end
end
call_callback(result) click to toggle source
# File lib/tarantool/response.rb, line 43
def call_callback(result)
  cb.call(Exception === result || get_tuples != :first ? result : result.first)
end
parse_response(data) click to toggle source
# File lib/tarantool/response.rb, line 47
def parse_response(data)
  return data  if Exception === data
  unless get_tuples
    ::BinUtils.get_int32_le(data)
  else
    tuples = unpack_tuples(data)
    if translators
      translators.each{|trans|
        tuples.map!{|tuple| trans.call(tuple)}
      }
    end
    tuples
  end
end
return_code(data) click to toggle source
# File lib/tarantool/response.rb, line 161
def return_code(data)
  ::BinUtils.slice_int32_le!(data)
end
translators() click to toggle source
# File lib/tarantool/response.rb, line 39
def translators
  super || (self.translators = [])
end
unpack_tuples(data) click to toggle source
# File lib/tarantool/response.rb, line 62
def unpack_tuples(data)
  tuples_affected = ::BinUtils.slice_int32_le!(data)
  tuples = []
  fields = fields()
  if Integer === fields.last
    *fields, tail = fields
  else
    tail = 1
  end

  while tuples_affected > 0
    byte_size = ::BinUtils.slice_int32_le!(data)
    fields_num = ::BinUtils.slice_int32_le!(data)
    tuple_str = data.slice!(0, byte_size)
    i = 0
    tuple = []
    while i < fields_num
      field_size = ::BinUtils.slice_ber!(tuple_str)

      field = fields[i] || get_tail_item(fields, i, tail)

      tuple << (field_size == 0 ? nil :
        case field
        when :int, :integer
          if field_size != 4
            raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
          end
          ::BinUtils.slice_int32_le!(tuple_str)
        when :string, :str
          str = tuple_str.slice!(0, field_size)
          str[0,1] = EMPTY  if str < ONE
          str.force_encoding(UTF8)
        when :int64
          if field_size != 8
            raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
          end
          ::BinUtils.slice_int64_le!(tuple_str)
        when :bytes
          tuple_str.slice!(0, field_size)
        when :int16
          if field_size != 2
            raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
          end
          ::BinUtils.slice_int16_le!(tuple_str)
        when :int8
          if field_size != 1
            raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
          end
          ::BinUtils.slice_int8!(tuple_str)
        when :sint
          if field_size != 4
            raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
          end
          ::BinUtils.slice_sint32_le!(tuple_str)
        when :sint64
          if field_size != 8
            raise ValueError, "Bad field size #{field_size} for 64bit integer field ##{i}"
          end
          ::BinUtils.slice_sint64_le!(tuple_str)
        when :sint16
          if field_size != 2
            raise ValueError, "Bad field size #{field_size} for 16bit integer field ##{i}"
          end
          ::BinUtils.slice_sint16_le!(tuple_str)
        when :sint8
          if field_size != 1
            raise ValueError, "Bad field size #{field_size} for 8bit integer field ##{i}"
          end
          ::BinUtils.slice_sint8!(tuple_str)
        when :varint
          case field_size
          when 8
            ::BinUtils.slice_int64_le!(tuple_str)
          when 4
            ::BinUtils.slice_int32_le!(tuple_str)
          when 2
            ::BinUtils.slice_int16_le!(tuple_str)
          else
            raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
          end
        when :auto
          str = tuple_str.slice!(0, field_size).force_encoding('utf-8')
          case field_size
          when 8, 4, 2
            Util::AutoType.new(str)
          else
            str
          end
        else
          get_serializer(field).decode(tuple_str.slice!(0, field_size))
        end)
      i += 1
    end
    tuples << tuple
    tuples_affected -= 1
  end
  tuples
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.