Crate dcbor_parse

Source
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 a CBOR object.
  • compose_dcbor_array: Composes a CBOR array from a slice of strings representing dCBOR items in diagnostic notation.
  • compose_dcbor_map: Composes a CBOR map from a slice of strings representing the key-value pairs in dCBOR diagnostic notation.
TypeExample(s)
Booleantrue
false
Nullnull
Integers0
1
-1
42
Floats3.14
-2.5
Infinity
-Infinity
NAN
Strings"hello"
"🌎"
Hex Byte Stringsh'68656c6c6f'
Base64 Byte Stringsb64'AQIDBAUGBwgJCg=='
Tagged Values1234("hello")
5678(3.14)
Name-Tagged Valuestag-name("hello")
tag-name(3.14)
Known Values'1'
'isA'
Unit Known ValueUnit
''
'0'
URsur: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§

ComposeError
ParseError

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.

Type Aliases§

ComposeResult
ParseResult