Class: Aerospike::Unpacker

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

Defined Under Namespace

Classes: MsgPackExt

Constant Summary collapse

@@pool =
Pool.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnpacker

Returns a new instance of Unpacker.



46
47
48
49
50
51
# File 'lib/aerospike/utils/unpacker.rb', line 46

def initialize
  @unpacker = MessagePack::Unpacker.new
  MsgPackExt::TYPES.each do |type|
    @unpacker.register_type(type) { |data| MsgPackExt.new(type, data) }
  end
end

Class Method Details

.useObject



29
30
31
32
33
34
35
# File 'lib/aerospike/utils/unpacker.rb', line 29

def self.use
  unpacker = @@pool.poll
  unpacker.reset
  yield unpacker
ensure
  @@pool.offer(unpacker)
end

Instance Method Details

#resetObject



62
63
64
# File 'lib/aerospike/utils/unpacker.rb', line 62

def reset
  @unpacker.reset
end

#unpack(bytes) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/aerospike/utils/unpacker.rb', line 53

def unpack(bytes)
  obj = @unpacker.feed(bytes).read
  case obj
  when Array then unpack_list(obj)
  when Hash  then unpack_map(obj)
  else obj
  end
end