Class: Tarantool::Response
- Inherits:
-
Object
- Object
- Tarantool::Response
- Defined in:
- lib/tarantool/response.rb
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#tuples ⇒ Object
readonly
Returns the value of attribute tuples.
-
#tuples_affected ⇒ Object
readonly
Returns the value of attribute tuples_affected.
Instance Method Summary collapse
-
#initialize(data, params = {}) ⇒ Response
constructor
A new instance of Response.
-
#tuple ⇒ Object
Only select request can return many tuples.
- #unpack_field(data) ⇒ Object
- #unpack_tuple(data) ⇒ Object
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
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
23 24 25 |
# File 'lib/tarantool/response.rb', line 23 def offset @offset end |
#tuples ⇒ Object (readonly)
Returns the value of attribute tuples.
23 24 25 |
# File 'lib/tarantool/response.rb', line 23 def tuples @tuples end |
#tuples_affected ⇒ Object (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
#tuple ⇒ Object
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 |