deser-cbor
CBOR support for deser. CBOR is a compact binary format with the data model of JSON plus byte strings and tags. Use this crate when you want smaller payloads than JSON without giving up a self describing format, or when you need to talk to CBOR based protocols (COSE, WebAuthn, ...).
The same types you use with JSON work unchanged, but bytes become native byte strings instead of base64 and UUIDs, date-times and big numbers use their standard CBOR tags:
use ;
let blob = Blob ;
// CBOR has native bytes
let cbor = to_vec.unwrap;
assert_eq!;
assert_eq!;
// JSON falls back to base64 for the very same type
assert_eq!;
- Reads all well-formed CBOR including indefinite length strings, arrays and maps and CBOR sequences.
- Writes the preferred serialization (shortest integers, lengths and
lossless floats).
SerializerConfig::set_canonicaladditionally sorts map entries for a deterministic encoding (for instance for signing). - Date-times (tags 0, 1 and 1004), UUIDs (tag 37), decimal fractions
(tag 4) and bignums (tags 2 and 3) map onto deser's well-known types, so
uuid::Uuid,jiff,chrono,timeandrust_decimaltypes work with the respective features of deser. - Other tags are transparent,
Tagged<T>reads and writes them. - Deeply nested input does not overflow the stack.
- CBOR sequences are read with a
Deserializerand written with aSerializer. from_readerandto_writerwork withstd::io, and the configurations read and write CBOR sequences on streams withdeser::ioor async runtimes (deser-tokio). Items are parsed while their input arrives, so only incomplete items (like strings) are buffered.