I'm working on serializing some objects so we can pass them to a lua script (which uses cmsgpack in Redis) and that doesn't have support for extensions.
So I'm creating a GenericMessagePacker helper class:
# frozen_string_literal: true
# There are scenarios where we can't use the default message packer because Rails
# registers types that we can't register in lua-cmsgpack
class GenericMessagePacker
def self.pack(obj)
factory.dump(obj)
end
def self.unpack(str)
factory.load(str)
end
def self.factory
@factory ||= MessagePack::Factory.new
end
end
The object I'm trying to serialize is the attributes from an ActiveRecord model (using attributes(enums_as: :symbols))
Nothing particularly fancy, but for some reason, when I serialize this object, I get a messagepack object which has a buffer in it (according to this converter)
Update, it seems like it's using write_bin under the hood, this is due to the string being encoding as ASCII-8BIT, I'll force some encoding here to avoid this
Running on msgpack-ruby 1.7.2
I'm working on serializing some objects so we can pass them to a lua script (which uses cmsgpack in Redis) and that doesn't have support for extensions.
So I'm creating a
GenericMessagePacker
helper class:The object I'm trying to serialize is the attributes from an ActiveRecord model (using
attributes(enums_as: :symbols)
)Nothing particularly fancy, but for some reason, when I serialize this object, I get a messagepack object which has a buffer in it (according to this converter)
The very odd bit to me, since I don't have any types registered, and the
buffer
cannot be decoded bylua-cmsgpack
Even more peculiarly, if I create the hash from scratch:
This does return the standard strings:
What am I missing here? Why am I seeing
buffer
as a type?