View Source jhn_cbor (jhn_stdlib v5.0.6)
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(), _}
Summary
Functions
Decodes the binary into a tuple of structured Erlang term.
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.
Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> CBOR.
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.
Types
-type opts() :: [opt()].
-type simple() :: true | false | null | undefined | {simple, integer()}.
-type tag() :: {tag, integer(), tag_content()} | {tag, tag_alias(), tag_content()}.
-type tag_alias() ::
timestamp | posix | bignum | decimal_fraction | bigfloat | embedded | uri | base64url |
base64 | mac | cbor.
-type tag_content() :: _.
Functions
Decodes the binary into a tuple of structured Erlang term.
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.
Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, []) -> CBOR.
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.