Class: Aerospike::MapValue

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

Overview

Map value. Supported by Aerospike 3 servers only.

Constant Summary

Constants inherited from Value

Value::INTEGER_RANGE

Instance Method Summary collapse

Methods inherited from Value

of

Constructor Details

#initialize(vmap) ⇒ MapValue

:nodoc:



407
408
409
410
411
412
413
414
415
416
# File 'lib/aerospike/value/value.rb', line 407

def initialize(vmap)
  @vmap = vmap || {}

  Packer.use do |packer|
    pack(packer)
    @bytes = packer.bytes
  end

  self
end

Instance Method Details

#estimate_sizeObject



418
419
420
# File 'lib/aerospike/value/value.rb', line 418

def estimate_size
  @bytes.bytesize
end

#getObject



440
441
442
# File 'lib/aerospike/value/value.rb', line 440

def get
  @vmap
end

#pack(packer) ⇒ Object



427
428
429
430
431
432
433
434
# File 'lib/aerospike/value/value.rb', line 427

def pack(packer)
  packer.write_map_header(@vmap.length)
  # @vmap.each do |key, val|
  for key, val in @vmap
    Value.of(key).pack(packer)
    Value.of(val).pack(packer)
  end
end

#to_bytesObject



444
445
446
# File 'lib/aerospike/value/value.rb', line 444

def to_bytes
  @bytes
end

#to_sObject



448
449
450
# File 'lib/aerospike/value/value.rb', line 448

def to_s
  @vmap.map{|k, v| "#{k.to_s} => #{v.to_s}" }.to_s
end

#typeObject



436
437
438
# File 'lib/aerospike/value/value.rb', line 436

def type
  Aerospike::ParticleType::MAP
end

#write(buffer, offset) ⇒ Object



422
423
424
425
# File 'lib/aerospike/value/value.rb', line 422

def write(buffer, offset)
  buffer.write_binary(@bytes, offset)
  @bytes.bytesize
end