Skip to content

Cbor

Functions for encoding and decoding CBOR (Concise Binary Object Representation) data.

CBOR is a binary data format designed for compact data representation and efficient parsing. It supports all JSON data types plus additional types like byte strings, tags, and simple values.

Examples

Encoding Values to CBOR

Values can be encoded to CBOR using Cbor.encode:

import { Cbor } from 'ox'
 
Cbor.encode({ foo: 'bar', baz: [1, 2, 3] })
'0xa263666f6f636261726362617a83010203'

Decoding CBOR to Values

Values can be decoded from CBOR using Cbor.decode:

import { Cbor } from 'ox'
 
Cbor.decode('0xa263666f6f636261726362617a83010203')
{ foo: 'bar', baz: [1, 2, 3] }

Functions

NameDescription
Cbor.decodeDecodes CBOR (Concise Binary Object Representation) data into a JavaScript value.
Cbor.encodeEncodes a value into CBOR (Concise Binary Object Representation) format.

Errors

NameDescription
Cbor.ArrayTooLargeError
Cbor.ByteStringTooLargeError
Cbor.InvalidAdditionalInfoError
Cbor.InvalidIndefiniteLengthChunkError
Cbor.InvalidMajorTypeError
Cbor.InvalidSimpleValueError
Cbor.NumberTooLargeError
Cbor.ObjectTooLargeError
Cbor.StringTooLargeError
Cbor.UnexpectedTokenError
Cbor.Unsupported64BitIntegerError
Cbor.UnsupportedBigIntError
Cbor.UnsupportedTagError