Skip to content

v0.2.0

Compare
Choose a tag to compare
@jeffective jeffective released this 28 Dec 21:59
· 49 commits to main since this release

v0.2.0 adds a ton of new features!.

  • Decode and encode variable length data structures (slices etc.) using an allocator.
  • Customize the format of types that could correspond to multiple MessagePack Types.

Default Formats

Zig Type MessagePack Type
bool bool
null nil
u3,u45, i6 integer
?T nil or T
enum integer
[N]T N length array of T
[N:x]T N+1 length array of T ending in x
[N]u8 str
@Vector(N, T) N length array of T
struct map, str: field value
union (enum) map (single key-value pair)
[]T N length array of T
[:x]T N + 1 length array of T ending in x
[]u8 str
[:x]u8 str ending in x
*T T

str is the default MessagePack type for []u8 because it is the smallest for short slices.

Unsupported types:

Zig Type Reason
union (untagged) Decoding cannot determine active field, and neither can you.
error I can add this, if someone asks. Perhaps as str?

Note: pointer types require allocation to decode.

Customizing Formats

You can customize how types are formatted in message pack:

Zig Type Available Encodings
enum string, int
[]u8,[N]u8 string, int, array
struct map, array
union (enum) map (single key-value pair), active field

See examples for how to do it.