Zig CBOR - A fast & flexible CBOR encoding, decoding, and pattern-matching library

Although I’ve been using this library for years in neurocyte/flow and neurcyte/thespian, I don’t think I’ve ever mentioned it here. Now that I’ve cut a new release and brushed up the documentation a bit I think it’s maybe worth a mention. So here goes.

https://codeberg.org/neurocyte/cbor

Zig CBOR

A fast & flexible CBOR (RFC 8949) encoding, decoding, and pattern-matching library for Zig 0.15+.


Features

  • Zero-allocation encoding - write directly into a caller-supplied buffer or use the streaming writer API

  • Expressive pattern matching - match CBOR values against rich patterns including type sentinels, wildcards, and nested structures

  • Typed extraction - pull values out of a CBOR stream directly into Zig variables, structs, unions, enums, and optionals

  • JSON interop - convert CBOR ↔ JSON with both allocating and non-allocating variants

  • Custom encode/decode hooks - any type can implement cborEncode / cborExtract to control its own serialisation

  • Full type coverage - integers (all widths + signs), floats (f16/f32/f64), booleans, null, strings, byte strings, arrays, maps, tagged unions, structs, enums, optionals, slices, vectors, error sets

7 Likes

Hey nice, it might be useful, for the lib itself but also for the language, to try to list it here: CBOR — Concise Binary Object Representation | Implementations