src/derails/passive_resistance/message_pack.rb
# frozen_string_literal: true

begin
  gem "msgpack", ">= 1.7.0"
  require "msgpack"
rescue LoadError => error
  warn "PassiveResistance::MessagePack requires the msgpack gem, version 1.7.0 or later. " \
    "Please add it to your Gemfile: `gem \"msgpack\", \">= 1.7.0\"`"
  raise error
end

require_relative "message_pack/cache_serializer"
require_relative "message_pack/serializer"

module PassiveResistance
  module MessagePack
    extend Serializer

    ##
    # :singleton-method: dump
    # :call-seq: dump(object)
    #
    # Dumps an object. Raises PassiveResistance::MessagePack::UnserializableObjectError
    # if the object type is not supported.
    #
    #--
    # Implemented by Serializer#dump.

    ##
    # :singleton-method: load
    # :call-seq: load(dumped)
    #
    # Loads an object dump created by ::dump.
    #
    #--
    # Implemented by Serializer#load.

    ##
    # :singleton-method: signature?
    # :call-seq: signature?(dumped)
    #
    # Returns true if the given dump begins with an +PassiveResistance::MessagePack+
    # signature.
    #
    #--
    # Implemented by Serializer#signature?.

    PassiveResistance.run_load_hooks(:message_pack, self)
  end
end
