class Droonga::MessagePackPacker

Constants

MICRO_SECONDS_DECIMAL_PLACE
VERSION

Public Class Methods

new() click to toggle source
# File lib/droonga/message-pack-packer.rb, line 33
def initialize
  @packer = MessagePack::Packer.new
end
pack(object) click to toggle source
# File lib/droonga/message-pack-packer.rb, line 24
def pack(object)
  packer = new
  packer.pack(object)
  packer.to_s
end

Public Instance Methods

clear() click to toggle source
# File lib/droonga/message-pack-packer.rb, line 66
def clear
  @packer.clear
end
pack(object) click to toggle source
# File lib/droonga/message-pack-packer.rb, line 37
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
    case object.class.name
    when "Groonga::WGS84GeoPoint", "Groonga::TokyoGeoPoint"
      @packer.write(GeoPointFormatter.format(object))
    else
      @packer.write(object)
    end
  end
end
to_s() click to toggle source
# File lib/droonga/message-pack-packer.rb, line 62
def to_s
  @packer.to_s
end