123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::MessagePack::Serializer

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Defined in: activesupport/lib/active_support/message_pack/serializer.rb

Constant Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#message_pack_factory (rw)

[ GitHub ]

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

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

#message_pack_factory=(factory) (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/message_pack/serializer.rb', line 35

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

#register_type (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/message_pack/serializer.rb', line 40

delegate :register_type, to: :message_pack_factory

Instance Method Details

#dump(object)

[ GitHub ]

  
# File 'activesupport/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

#install_unregistered_type_handler (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/message_pack/serializer.rb', line 58

def install_unregistered_type_handler
  Extensions.install_unregistered_type_error(message_pack_factory)
end

#load(dumped)

[ GitHub ]

  
# File 'activesupport/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_pool (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/message_pack/serializer.rb', line 47

def message_pack_pool
  @message_pack_pool ||= begin
    unless message_pack_factory.frozen?
      Extensions.install(message_pack_factory)
      install_unregistered_type_handler
      message_pack_factory.freeze
    end
    message_pack_factory.pool(ENV.fetch("RAILS_MAX_THREADS", 5).to_i)
  end
end

#signature?(dumped) ⇒ Boolean

[ GitHub ]

  
# File 'activesupport/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

#warmup

[ GitHub ]

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

def warmup
  message_pack_pool # eagerly compute
end