Expand description
dCBOR: Deterministic CBOR Codec
dcbor is a CBOR codec that focuses on writing and
parsing “deterministic” CBOR per §4.2 of
RFC-8949.
It does not support parts of the spec forbidden by deterministic CBOR (such
as indefinite length arrays and maps). It is strict in both what it
writes and reads: in particular it will throw decoding errors if
variable-length integers are not encoded in their minimal form, or CBOR map
keys are not in lexicographic order, or there is extra data past the end of
the decoded CBOR item.
Getting Started
Add the following to your Cargo.toml:
[dependencies]
dcbor = "0.3.1"
Usage
Encode an array of strings as CBOR.
use dcbor::*;
let array = ["A", "B", "C"];
let cbor = array.cbor();
assert_eq!(cbor.hex(), "83614161426143")Decode CBOR binary back to an array of strings.
use dcbor::*;
let data = hex::hex_to_data("83614161426143");
let cbor = CBOR::from_data(&data).unwrap();
assert_eq!(cbor.diagnostic(), r#"["A", "B", "C"]"#);
let array = Vec::<String>::from_cbor(&cbor).unwrap();
assert_eq!(format!("{:?}", array), r#"["A", "B", "C"]"#);See the unit tests For further examples, including encoding and decoding arrays with heterogenous elements, maps, and user-defined types with custom CBOR tags.
Modules
- Utilities for converting between binary data and hexadecimal strings.
Structs
- A CBOR byte string.
- A CBOR-friendly representation of a date and time.
- A concrete type that maps from tags to their known names.
- A CBOR map.
- An iterator over the entries of a CBOR map.
- A CBOR tag.
- A CBOR tagged value.
Enums
- A symbolic representation of CBOR data.
- An error encountered while decoding CBOR.
- A CBOR simple value.
Traits
- A type that can be encoded to or decoded from CBOR.
- A type that can be decoded from CBOR.
- A type that can be encoded as CBOR.
- A type that can be encoded to or from CBOR with a specific tag.
- A type that can be decoded from CBOR with a specific tag.
- A type that can be encoded to CBOR with a specific tag.
- A type that can return the name for a tag.