Class: Tarantool::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/tarantool/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, params = {}) ⇒ Response

Returns a new instance of Response.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tarantool/response.rb', line 24

def initialize(data, params = {})
  @offset = 0
  @tuples_affected, = data[0, 4].unpack('L')
  @offset += 4
  if params[:return_tuple]
    @tuples = (1..tuples_affected).map do
      unpack_tuple(data)
    end
  else
    tuples_affected
  end
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



23
24
25
# File 'lib/tarantool/response.rb', line 23

def offset
  @offset
end

#tuplesObject (readonly)

Returns the value of attribute tuples.



23
24
25
# File 'lib/tarantool/response.rb', line 23

def tuples
  @tuples
end

#tuples_affectedObject (readonly)

Returns the value of attribute tuples_affected.



23
24
25
# File 'lib/tarantool/response.rb', line 23

def tuples_affected
  @tuples_affected
end

Instance Method Details

#tupleObject

Only select request can return many tuples



38
39
40
# File 'lib/tarantool/response.rb', line 38

def tuple
  tuples.first
end

#unpack_field(data) ⇒ Object



52
53
54
55
56
# File 'lib/tarantool/response.rb', line 52

def unpack_field(data)
  byte_size,  = data.unpack('w')
  data.slice!(0, [byte_size].pack('w').bytesize) # ololo
  data.slice!(0, byte_size)
end

#unpack_tuple(data) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/tarantool/response.rb', line 42

def unpack_tuple(data)
  byte_size, cardinality = data[offset, 8].unpack("LL")
  @offset += 8
  tuple_data = data[offset, byte_size]
  @offset += byte_size
  (1..cardinality).map do
    Field.new unpack_field(tuple_data)
  end
end