@insler/serde-cbor
The CBOR adapter package: cborSerde, a Serde<Uint8Array> backed by
cbor2. Reach for it when CBOR’s
compact, self-describing binary encoding (RFC 8949) is wanted on a binary
wire.
bun add @insler/serde-cborcborSerde — Serde<Uint8Array>
Section titled “cborSerde — Serde<Uint8Array>”import { cborSerde } from '@insler/serde-cbor';
const bytes = cborSerde.encode({ id: 'ord-1', quantity: 3, price: 19.5 });// Uint8Array — CBOR-encoded
const order = cborSerde.decode(bytes);// { id: 'ord-1', quantity: 3, price: 19.5 }It honors the shared serde conventions: encode(undefined) produces empty
bytes, decoding empty bytes returns undefined.
Interchangeable behind the interface
Section titled “Interchangeable behind the interface”cborSerde is a standard Serde<Uint8Array> — swap it with
jsonBytesSerde,
msgpackSerde, or an
Avro serde wherever a binary serde is accepted,
such as the rpc subsystem’s NATS transport serde
option.
Boundaries
Section titled “Boundaries”Depends on @insler/serde (the interface) and cbor2 — it is
transport-agnostic by design, coupled to nothing but the Serde<Uint8Array>
seam.