class Tarantool::Response
Public Instance Methods
call(data)
click to toggle source
# File lib/tarantool/response.rb, line 103 def call(data) if Exception === data cb.call(data) else if (ret = return_code(data)) == 0 call_callback parse_response_for_cb(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 120 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 130 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
parse_response_for_cb(data)
click to toggle source
# File lib/tarantool/response.rb, line 124 def parse_response_for_cb(data) parse_response data rescue StandardError => e e end
return_code(data)
click to toggle source
# File lib/tarantool/response.rb, line 179 def return_code(data) ::BinUtils.slice_int32_le!(data) end
translators()
click to toggle source
Calls superclass method
# File lib/tarantool/response.rb, line 116 def translators super || (self.translators = []) end
unpack_tuples(data)
click to toggle source
# File lib/tarantool/response.rb, line 145 def unpack_tuples(data) tuples_affected = ::BinUtils.slice_int32_le!(data) ta = tuples_affected fields = fields() if Integer === fields.last *fields, tail = fields else tail = 1 end orig_data = data.dup begin tuples = [] serializers = [] 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 = fields[fieldno = i] || fields[fieldno = get_tail_no(fields, i, tail)] tuple << _unpack_field(tuple_str, field, i, fieldno, serializers) i += 1 end tuples << tuple tuples_affected -= 1 end tuples rescue ValueError => e $stderr.puts "Value Error: tuples=#{ta} now=#{ta-tuples_affected}, remains=#{data.bytesize} remains_data='#{data.unpack('H*')[0].gsub(/../,'\& ')}' orig_size=#{orig_data.size} orig_data='#{orig_data.unpack('H*')[0].gsub(/../,'\& ')}'" raise e end end