MessagePack
Parsing
Serde.SerdeMsgPack.parse_msgpack — Function
parse_msgpack(x::Vector{UInt8}) -> AnyDecode a MessagePack byte array into Julia data structures without mapping to a target type.
Returns the raw decoded value: a Dict{String,Any} for MsgPack maps, a Vector{Any} for arrays, or a scalar (Int64, Float64, String, Bool, Nothing, DateTime, Vector{UInt8}) for primitive values.
The MsgPack timestamp extension type (-1) is decoded as DateTime.
Arguments
x::Vector{UInt8}: the raw MessagePack bytes.
Returns
The decoded Julia value.
Throws
ParseError: ifxcontains invalid MessagePack.
Examples
julia> bytes = to_msgpack(Dict("x" => 1, "y" => 2));
julia> parse_msgpack(bytes)
Dict{String, Any}("x" => 1, "y" => 2)See also: from_msgpack, try_from_msgpack.
Deserialization
Serde.SerdeMsgPack.from_msgpack — Function
from_msgpack(::Type{T}, x::Vector{UInt8}) -> T
from_msgpack(strategy, ::Type{T}, x::Vector{UInt8}) -> T
from_msgpack(f::Function, x::Vector{UInt8}) -> AnyDecode a MessagePack byte array and deserialize it into type T.
Pass a context object strategy (e.g. CamelCase()) to apply global field-renaming.
Arguments
::Type{T}: target type to construct.x::Vector{UInt8}: raw MsgPack bytes.strategy: optional context object.
Returns
A value of type T.
Throws
ParseError: ifxis invalid MsgPack.MissingFieldError: if a required struct field is absent.TypeMismatchError: if a value cannot be coerced to the field type.
Examples
julia> struct Point; x::Int; y::Int; end
julia> bytes = to_msgpack(Point(1, 2));
julia> from_msgpack(Point, bytes)
Point(1, 2)See also: try_from_msgpack, to_msgpack, parse_msgpack.
Serde.SerdeMsgPack.try_from_msgpack — Function
try_from_msgpack(::Type{T}, x::Vector{UInt8}) -> Union{T, SerdeError}
try_from_msgpack(strategy, ::Type{T}, x::Vector{UInt8}) -> Union{T, SerdeError}Like from_msgpack but returns a SerdeError instead of throwing on failure.
Returns
Ton success.- A
ParseErrororDeserErrorsubtype on failure.
See also: from_msgpack, SerdeError.
Serialization
Serde.SerdeMsgPack.to_msgpack — Function
to_msgpack(data) -> Vector{UInt8}
to_msgpack(strategy, data) -> Vector{UInt8}Serialize data into a MessagePack byte array.
Structs are encoded as MsgPack maps with string keys. Vector{UInt8} fields are encoded as MsgPack bin (binary). DateTime values use the MsgPack timestamp extension (-1). nothing and missing are encoded as nil.
Pass a context object strategy (e.g. CamelCase()) to apply global field-renaming.
All serialization traits (Serde.ser_name, Serde.ser_value, Serde.ser_skip) are applied.
Arguments
data: the value to serialize.strategy: optional context object.
Returns
Vector{UInt8} — the raw MsgPack bytes.
Examples
julia> struct Point; x::Int; y::Int; end
julia> bytes = to_msgpack(Point(1, 2));
julia> from_msgpack(Point, bytes)
Point(1, 2)See also: from_msgpack.