MessagePack

Parsing

Serde.SerdeMsgPack.parse_msgpackFunction
parse_msgpack(x::Vector{UInt8}) -> Any

Decode 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

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.

source

Deserialization

Serde.SerdeMsgPack.from_msgpackFunction
from_msgpack(::Type{T}, x::Vector{UInt8}) -> T
from_msgpack(strategy, ::Type{T}, x::Vector{UInt8}) -> T
from_msgpack(f::Function, x::Vector{UInt8}) -> Any

Decode 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

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.

source

Serialization

Serde.SerdeMsgPack.to_msgpackFunction
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.

source