Skip to content

Commit

Permalink
Check if MessagePack::Timestamp is defined to stay compatible with ms…
Browse files Browse the repository at this point in the history
…gpack ~> 1.0 [fix #349]
  • Loading branch information
byroot committed Feb 8, 2021
1 parent b9c5f5d commit b153657
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/bootsnap/compile_cache/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,25 @@ def init!
# see: https://github.com/msgpack/msgpack-ruby/pull/122
factory = MessagePack::Factory.new
factory.register_type(0x00, Symbol)
factory.register_type(
MessagePack::Timestamp::TYPE, # or just -1
Time,
packer: MessagePack::Time::Packer,
unpacker: MessagePack::Time::Unpacker
)

marshal_fallback = {
packer: ->(value) { Marshal.dump(value) },
unpacker: ->(payload) { Marshal.load(payload) },
}
{
Date => 0x01,
Regexp => 0x02,
}.each do |type, code|
factory.register_type(code, type, marshal_fallback)
if defined? MessagePack::Timestamp
factory.register_type(
MessagePack::Timestamp::TYPE, # or just -1
Time,
packer: MessagePack::Time::Packer,
unpacker: MessagePack::Time::Unpacker
)

marshal_fallback = {
packer: ->(value) { Marshal.dump(value) },
unpacker: ->(payload) { Marshal.load(payload) },
}
{
Date => 0x01,
Regexp => 0x02,
}.each do |type, code|
factory.register_type(code, type, marshal_fallback)
end
end

self.msgpack_factory = factory
Expand Down

0 comments on commit b153657

Please sign in to comment.