Class: Aerospike::Unpacker
- Inherits:
-
Object
- Object
- Aerospike::Unpacker
- Defined in:
- lib/aerospike/utils/unpacker.rb
Defined Under Namespace
Classes: MsgPackExt
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Unpacker
constructor
A new instance of Unpacker.
- #reset ⇒ Object
- #unpack(bytes) ⇒ Object
Constructor Details
#initialize ⇒ Unpacker
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
.use ⇒ Object
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
#reset ⇒ Object
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 |