Method: Aerospike::MultiCommand#parse_result

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

#parse_resultObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/aerospike/command/multi_command.rb', line 45

def parse_result
  # Read socket into receive buffer one record at a time.  Do not read entire receive size
  # because the receive buffer would be too big.
  status = true

  while status
    @data_offset = 0
    @compressed_data_buffer = nil

    # Read header.
    read_bytes(8)

    size = @data_buffer.read_int64(0)
    receive_size = size & 0xFFFFFFFFFFFF

    # inflate if compressed
    compressed_sz = compressed_size
    if compressed_sz
      begin
        # read compressed msg header
        @conn.read(@data_buffer, 8)

        # read compressed message
        @conn.read(@data_buffer, compressed_sz - 8)

        # inflate the results
        # TODO: reuse the current buffer
        uncompressed = Zlib.inflate(@data_buffer.buf)
        receive_size = uncompressed.size - 8

        @compressed_data_buffer = Buffer.new(-1, uncompressed)
        @compressed_data_offset = 0

        # waste the first 8 header bytes
        @compressed_data_buffer.eat!(8)
      rescue => e
        Aerospike.logger.error("parse result error: #{e}")
        raise e
      end
    end

    status = if receive_size > 0
      parse_group(receive_size)
             else
      false
             end
  end
end