Module: ActiveSupport::MessagePack::Serializer

Included in:
ActiveSupport::MessagePack, CacheSerializer
Defined in:
lib/active_support/message_pack/serializer.rb

Overview

:nodoc:

Constant Summary collapse

SIGNATURE =

128.to_msgpack

"\xCC\x80".b.freeze
SIGNATURE_INT =
128

Instance Method Summary collapse

Instance Method Details

#dump(object) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/active_support/message_pack/serializer.rb', line 11

def dump(object)
  message_pack_pool.packer do |packer|
    packer.write(SIGNATURE_INT)
    packer.write(object)
    packer.full_pack
  end
end

#load(dumped) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/active_support/message_pack/serializer.rb', line 19

def load(dumped)
  message_pack_pool.unpacker do |unpacker|
    unpacker.feed_reference(dumped)
    raise "Invalid serialization format" unless unpacker.read == SIGNATURE_INT
    unpacker.full_unpack
  end
end

#message_pack_factoryObject



31
32
33
# File 'lib/active_support/message_pack/serializer.rb', line 31

def message_pack_factory
  @message_pack_factory ||= ::MessagePack::Factory.new
end

#message_pack_factory=(factory) ⇒ Object



35
36
37
38
# File 'lib/active_support/message_pack/serializer.rb', line 35

def message_pack_factory=(factory)
  @message_pack_pool = nil
  @message_pack_factory = factory
end

#signature?(dumped) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/active_support/message_pack/serializer.rb', line 27

def signature?(dumped)
  dumped.getbyte(0) == SIGNATURE.getbyte(0) && dumped.getbyte(1) == SIGNATURE.getbyte(1)
end

#warmupObject



42
43
44
# File 'lib/active_support/message_pack/serializer.rb', line 42

def warmup
  message_pack_pool # eagerly compute
end