gbor/decode
Tools for decoding binary CBOR data into Gleam types
Types
The error type for decoding CBOR data into Gleam types
pub type CborDecodeError {
DynamicDecodeError(List(decode.DecodeError))
MajorTypeError(Int)
ReservedError
UnimplementedError(String)
UnassignedError
}
Constructors
-
DynamicDecodeError(List(decode.DecodeError))
-
MajorTypeError(Int)
-
ReservedError
-
UnimplementedError(String)
-
UnassignedError
Values
pub fn cbor_to_dynamic(cbor: gbor.CBOR) -> dynamic.Dynamic
Convert a CBOR Gleam value to a dynamic value for use with gleam/dynamic/decode
pub fn from_bit_array(
data: BitArray,
) -> Result(gbor.CBOR, CborDecodeError)
Decode a CBOR value from a bit array
This function is the main entry point for decoding CBOR data into Gleam types.
It takes a bit array and returns a result containing the decoded CBOR value
pub fn tagged_decoder(
expected_tag: Int,
decoder: decode.Decoder(a),
zero: a,
) -> decode.Decoder(a)
Decode a tagged CBOR value.
Provided tag is the expected tag number for the value, and the decoder is run on the value corresponding to the tag.
For example, for a CBOR value with a tag number of 0
, the expected data item
is a text string representing a standard time string, so one would call:
import gleam/dynamic/decode as gdd
tagged_decoder(0, gdd.string, "")
Reference: RFC 8949 : 3.4 Tagging of Items