Class: Droonga::MessagePackPacker

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/message-pack-packer.rb,
lib/droonga/message-pack-packer/version.rb,
lib/droonga/message-pack-packer/time-formatter.rb

Defined Under Namespace

Classes: TimeFormatter

Constant Summary collapse

MICRO_SECONDS_DECIMAL_PLACE =
6
VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessagePackPacker

Returns a new instance of MessagePackPacker.



32
33
34
# File 'lib/droonga/message-pack-packer.rb', line 32

def initialize
  @packer = MessagePack::Packer.new
end

Class Method Details

.pack(object) ⇒ Object



23
24
25
26
27
# File 'lib/droonga/message-pack-packer.rb', line 23

def pack(object)
  packer = new
  packer.pack(object)
  packer.to_s
end

Instance Method Details

#pack(object) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/droonga/message-pack-packer.rb', line 36

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_sObject



56
57
58
# File 'lib/droonga/message-pack-packer.rb', line 56

def to_s
  @packer.to_s
end