Module jhn_cbor

A CBOR library based on:.

Copyright © (C) 2021-2024, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

A CBOR library based on:

Concise Binary Object Representation (CBOR) (rfc8949)

IANA Considerations and IETF Protocol and Documentation Usage for IEEE 802 Parameters (rfc9542)

Supported tags:

rfc8949: 0, 1, 2, 3, 4, 5, 24, 32, 33, 34, 55799

rfc9542: 48

Tags unlikely to ever be supported: 21, 22, 23

CBOR cbor() values are represented as follows:

Simple values:

False(20) : false

True(21) : true

Null(22) : null

Undefined(23) : undefined

(Integer) : {simple, integer()}

Numbers:

Integer : integer()

Float : float() | {float16, float()} | {float32, float()} | {float64, float()} | inf | neg_inf | nan.

Bistrings:

String : {string, binary()}

indefinite length String : {strings, [{string, binary()}]}

Text : binary()

indefinite length Texts : {texts, [binary()]}

Collections:

Map : #{cbor() => cbor()}

indefinite length Map : {map, [#{cbor() => cbor()}]}

Array : [cbor()]

Arrays : {arrays, [cbor()]}

Tags:

timestamp(0) : {tag, timestamp, integer() | binary()}

posix(1) : {tag, posix, integer() | float() | null | undefined}

bignum(2) : {tag, bignum, non_neg_integer()}

bignum(3) : {tag, bignum, neg_integer()}

decimal_fraction(4) : {tag, decimal_fraction, {integer(), integer()}}

bigfloat(5) : {tag, bigfloat, {integer(), integer()}

embedded(24) : {tag, embedded, binary()}

uri(32) : {tag, uri, #uri{} | binary()}

base64url(33) : {tag, base64url, binary()}

base64(34) : {tag, based, binary()}

mac(48) : {tag, mac, binary()}

cbor(55799) : {tag, cbor, cbor()}

(Integer) : {tag, integer(), _}

Data Types

array()

array() = [cbor()] | {arrays, [[cbor()]]}

cbor()

cbor() = simple() | integer() | float() | cfloat() | cstring() | ctext() | cmap() | array() | tag()

cfloat()

cfloat() = {float16, float()} | {float32, float()} | {float64, float()} | inf | neg_inf | nan

cmap()

cmap() = #{cbor() => cbor()} | {maps, [#{cbor() => cbor()}]}

cstring()

cstring() = {string, binary()} | {strings, [{string, binary()}]}

ctext()

ctext() = binary() | {texts, [binary()]}

opt()

opt() = binary | iolist | continue | {tag_callbacks, [{integer(), atom()}]}

opts()

opts() = [opt()]

simple()

simple() = true | false | null | undefined | {simple, integer()}

tag()

tag() = {tag, integer(), tag_content()} | {tag, tag_alias(), tag_content()}

tag_alias()

tag_alias() = timestamp | posix | bignum | decimal_fraction | bigfloat | embedded | uri | base64url | base64 | mac | cbor

tag_content()

tag_content() = term()

Function Index

decode/1 Decodes the binary into a tuple of structured Erlang term.
decode/2 Decodes the binary into a structured Erlang term or a tuple of a structured Erlang term and the rest of the binary if the continue option is given.
encode/1 Encodes the structured Erlang term as an iolist.
encode/2 Encodes the structured Erlang term as an iolist or binary.

Function Details

decode/1

decode(Binary::binary()) -> {cbor(), binary()}

Decodes the binary into a tuple of structured Erlang term.

decode/2

decode(Binary::binary(), Opts::opts()) -> {cbor(), binary()}

Decodes the binary into a structured Erlang term or a tuple of a structured Erlang term and the rest of the binary if the continue option is given. A {tag_callbacks, [{integer(), nodule()}]} can supplied to specify a module with a cbor_decode_tag callback function to decode tags not supporrted in this module.

encode/1

encode(CBOR::cbor()) -> iodata()

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> CBOR.

encode/2

encode(T::cbor(), Opts::opts()) -> binary()

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> an iolist is returned (default) {tag_callbacks, [{integer(), nodule()}]} specifies a module with a cbor_encode_tag callback function to decode tags not supporrted in this module.


Generated by EDoc