Class: Droonga::MessagePackPacker
- Inherits:
-
Object
- Object
- Droonga::MessagePackPacker
- Defined in:
- lib/droonga/message_pack_packer.rb
Constant Summary collapse
- MICRO_SECONDS_DECIMAL_PLACE =
6
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ MessagePackPacker
constructor
A new instance of MessagePackPacker.
- #pack(object) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ MessagePackPacker
Returns a new instance of MessagePackPacker.
34 35 36 |
# File 'lib/droonga/message_pack_packer.rb', line 34 def initialize @packer = MessagePack::Packer.new end |
Class Method Details
.pack(object) ⇒ Object
25 26 27 28 29 |
# File 'lib/droonga/message_pack_packer.rb', line 25 def pack(object) packer = new packer.pack(object) packer.to_s end |
Instance Method Details
#pack(object) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/droonga/message_pack_packer.rb', line 38 def pack(object) case object when Array @packer.write_array_header(object.size) object.each do |element| pack(element) end when Hash @packer.write_map_header(object.size) object.each do |key, value| pack(key) pack(value) end when Time @packer.write(TimeFormatter.format(object)) else @packer.write(object) end end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/droonga/message_pack_packer.rb', line 58 def to_s @packer.to_s end |