Class: Aerospike::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/info.rb

Overview

Polymorphic value classes used to efficiently serialize objects into the wire protocol.

Class Method Summary collapse

Class Method Details

.parse_multiple_response(buf_length, buffer) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/aerospike/info.rb', line 57

def self.parse_multiple_response(buf_length, buffer)
  res = {}
  buffer.read(0, buf_length).split("\n").each do |vstr|
    k, v = vstr.split("\t")
    res[k] = v
  end
  res
end

.request(conn, *commands) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aerospike/info.rb', line 26

def self.request(conn, *commands)
  buffer = Buffer.get

  # If conservative estimate may be exceeded, get exact estimate
  # to preserve memory and resize buffer.
  offset = 8

  commands.each do |command|
    offset += command.bytesize + 1
  end

  buffer.resize(offset)

  offset = 8 # Skip size field.

  # The command format is: <name1>\n<name2>\n...
  commands.each do |command|
    buffer.write_binary(command, offset)
    offset += command.bytesize
    buffer.write_byte("\n", offset)
    offset += 1
  end

  begin
    buf_length = send_command(conn, offset, buffer)
    parse_multiple_response(buf_length, buffer)
  ensure
    Buffer.put(buffer)
  end
end