Class: Paquito::CodecFactory::MessagePackCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/paquito/codec_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(factory, freeze: false) ⇒ MessagePackCodec

Returns a new instance of MessagePackCodec.



27
28
29
30
# File 'lib/paquito/codec_factory.rb', line 27

def initialize(factory, freeze: false)
  @factory = factory
  @freeze = freeze
end

Instance Method Details

#dump(object) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/paquito/codec_factory.rb', line 32

def dump(object)
  @factory.dump(object)
rescue NoMethodError => error
  raise PackError.new(error.message, error.receiver)
rescue RangeError => error
  raise PackError, "#{error.class.name}, #{error.message}"
end

#load(payload) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/paquito/codec_factory.rb', line 40

def load(payload)
  if @freeze
    @factory.load(payload, freeze: @freeze)
  else
    @factory.load(payload)
  end
rescue MessagePack::UnpackError => error
  raise UnpackError, error.message
rescue IOError => error
  raise UnpackError, "#{error.class.name}, #{error.message}"
end