Method: Aerospike::ReadCommand#parse_record

Defined in:
lib/aerospike/command/read_command.rb

#parse_record(op_count, field_count, generation, expiration) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/aerospike/command/read_command.rb', line 153

def parse_record(op_count, field_count, generation, expiration)
  bins = op_count > 0 ? {} : nil
  receive_offset = 0
  single_bin_value = !policy.is_a?(OperatePolicy) || policy.record_bin_multiplicity == RecordBinMultiplicity::SINGLE

  # There can be fields in the response (setname etc).
  # But for now, ignore them. Expose them to the API if needed in the future.
  if field_count > 0
    # Just skip over all the fields
    i = 0
    while i < field_count
      field_size = @data_buffer.read_int32(receive_offset)
      receive_offset += (4 + field_size)
      i = i.succ
    end
  end

  i = 0
  while i < op_count
    op_size = @data_buffer.read_int32(receive_offset)
    particle_type = @data_buffer.read(receive_offset+5).ord
    name_size = @data_buffer.read(receive_offset+7).ord
    name = @data_buffer.read(receive_offset+8, name_size).force_encoding(BIN_NAME_ENCODING)
    receive_offset += 4 + 4 + name_size

    particle_bytes_size = op_size - (4 + name_size)
    value = Aerospike.bytes_to_particle(particle_type, @data_buffer, receive_offset, particle_bytes_size)
    receive_offset += particle_bytes_size

    if single_bin_value || !bins.has_key?(name)
      bins[name] = value
    elsif (prev = bins[name]).is_a?(OpResults)
      prev << value
    else
      bins[name] = OpResults.new << prev << value
    end

    i = i.succ
  end

  Record.new(@node, @key, bins, generation, expiration)
end