Expand description
§dCBOR Diagnostic Parser and Composer
This crate provides tools for parsing and composing the CBOR diagnostic notation into dCBOR (deterministic CBOR) data items.
It is intended for use in testing, debugging, the dcbor
command line tool,
and other scenarios where a human-readable representation of dCBOR is
useful. It is not optimized for performance and should not be used in
production environments where binary dCBOR is expected.
The primary functions provided are:
parse_dcbor_item
: Parses a string in CBOR diagnostic notation into aCBOR
object.compose_dcbor_array
: Composes aCBOR
array from a slice of strings representing dCBOR items in diagnostic notation.compose_dcbor_map
: Composes aCBOR
map from a slice of strings representing the key-value pairs in dCBOR diagnostic notation.
Type | Example(s) |
---|---|
Boolean | true false |
Null | null |
Integers | 0 1 -1 42 |
Floats | 3.14 -2.5 Infinity -Infinity NAN |
Strings | "hello" "🌎" |
Hex Byte Strings | h'68656c6c6f' |
Base64 Byte Strings | b64'AQIDBAUGBwgJCg==' |
Tagged Values | 1234("hello") 5678(3.14) |
Name-Tagged Values | tag-name("hello") tag-name(3.14) |
Known Values | '1' 'isA' |
Unit Known Value | Unit '' '0' |
URs | ur:date/cyisdadmlasgtapttl |
Arrays | [1, 2, 3] ["hello", "world"] [1, [2, 3]] |
Maps | {1: 2, 3: 4} {"key": "value"} {1: [2, 3], 4: 5} |
§Parsing Named Tags and Uniform Resources (URs)
A Uniform Resource (UR) is a URI representation of tagged dCBOR, where the tag is represented as a text type component. The last component of the UR is the untagged CBOR encoded as ByteWords, including a CRC-32 checksum in the last eight letters.
To parse named tags and URs, the correspondence between the tag name (UR
type) and the integer CBOR tag value must be known. This is done by using
the with_tags!
macro to access the global tags registry. Clients wishing
to parse named tags and URs must register the CBOR tag value and its
corresponding name in the global tags registry. The
dcbor
crate only registers one tag and
name for date
(tag 1). The bc-tags
crate registers many more. See the register_tags
functions in these crates
for examples of how to register your own tags.
Enums§
Functions§
- compose_
dcbor_ array - Composes a dCBOR array from a slice of string slices, and returns a CBOR object representing the array.
- compose_
dcbor_ map - Composes a dCBOR map from a slice of string slices, and returns a CBOR object representing the map.
- parse_
dcbor_ item - Parses a dCBOR item from a string input.