Hey
I’m using MsgPack.jl and trying to add an ExtentionType (Link). But I want to define my one deserialization as defined here.
I hope someone knows how it works
Hey
I’m using MsgPack.jl and trying to add an ExtentionType (Link). But I want to define my one deserialization as defined here.
I hope someone knows how it works
I don’t quite understand what you want to do, but something you can do is
using MsgPack, Dates
using Dates: Nanosecond
# Define how to serialize `Dates.Nanosecond`
MsgPack.msgpack_type(::Type{Nanosecond}) = MsgPack.IntegerType()
MsgPack.from_msgpack(::Type{Nanosecond}, x::Integer) = Nanosecond(x)
MsgPack.to_msgpack(::MsgPack.IntegerType, x::Nanosecond) = x.value
# Define some kind of timestamp object...
struct MyTimestamp
time::Nanosecond
end
# Tell MsgPack how to serialize it
MsgPack.msgpack_type(::Type{MyTimestamp}) = MsgPack.StructType()
# Give it a try
a = MyTimestamp(Nanosecond(100))
bytes = pack(a)
unpack(bytes, MyTimestamp) == a # returns `true`
I’m not sure that’s helpful but I figured I’d mention it, since I just learned about it today (Add `msgpack_type(::Type{TimeSpan})` by ericphanson · Pull Request #45 · beacon-biosignals/Onda.jl · GitHub).