Crate dcbor

Source
Expand description

§dCBOR: Deterministic CBOR Codec

dcbor is a reference implementation of Deterministic CBOR. The current specification of the norms and practices guiding the creation of this implementation are currently found in this IETF Internet Draft: draft-mcnally-deterministic-cbor.

§Getting Started

Add the following to your Cargo.toml:

[dependencies]
dcbor = "0.19.1"

§Features

§Multi-threaded

The multithreaded feature is available but not enabled by default. It uses Arc for reference counting instead of Rc. To enable it, add the following to your Cargo.toml:

[dependencies.dcbor]
version = "0.19.1"
features = ["multithreaded"]

§no_std

The dcbor library is no_std compatible. To use it in a no_std environment, disable the default features in your Cargo.toml and enable the no_std feature:

[dependencies.dcbor]
version = "0.19.1"
default-features = false
features = ["no_std"]

§Usage

Encode an array of integers as CBOR.

use dcbor::prelude::*;
let array = [1000, 2000, 3000];
let cbor: CBOR = array.into();
assert_eq!(cbor.hex(), "831903e81907d0190bb8");

Decode CBOR binary back to an array of integers.

use dcbor::prelude::*;
let data = hex_literal::hex!("831903e81907d0190bb8");
let cbor = CBOR::try_from_data(&data).unwrap();
assert_eq!(cbor.diagnostic(), "[1000, 2000, 3000]");
let array: Vec::<u32> = cbor.try_into().unwrap();
assert_eq!(format!("{:?}", array), "[1000, 2000, 3000]");

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§

prelude

Macros§

cbor_tag
const_cbor_tag
with_tags
A macro for accessing the global tags store in a read-only manner.
with_tags_mut
A macro for accessing the global tags store in a mutable manner.

Structs§

Arc
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
Box
A pointer type that uniquely owns a heap allocation of type T.
ByteString
Represents a CBOR byte string (major type 2).
CBOR
A symbolic representation of CBOR data.
Date
A CBOR-friendly representation of a date and time.
HashMap
A hash map implemented with quadratic probing and SIMD lookup.
HashSet
A hash set implemented as a HashMap where the value is ().
LazyTagsStore
Map
Map Support in dCBOR
MapIter
An iterator over the entries of a CBOR map.
Set
SetIter
String
A UTF-8–encoded, growable string.
Tag
Represents a CBOR tag (major type 6) with optional associated name.
TagsStore
A registry that maintains mappings between CBOR tags, their human-readable names, and optional summarizers.
Vec
A contiguous growable array type, written as Vec<T>, short for ‘vector’.

Enums§

CBORCase
An enum representing all possible CBOR data types.
Error
A comprehensive set of errors that can occur during CBOR encoding and decoding operations, with special focus on enforcing the deterministic encoding rules specified in the dCBOR specification.
Simple
Represents CBOR simple values (major type 7).

Constants§

TAG_DATE
TAG_NAME_DATE

Statics§

GLOBAL_TAGS

Traits§

CBORCodable
A trait for types that can be both encoded to and decoded from CBOR.
CBORDecodable
A trait for types that can be decoded from CBOR.
CBOREncodable
CBOR Encoding and Decoding Traits
CBORSortable
CBORTagged
CBOR Tagged Value Support
CBORTaggedCodable
Tagged CBOR Encoding and Decoding Support
CBORTaggedDecodable
Tagged CBOR Decoding Support
CBORTaggedEncodable
Tagged CBOR Encoding Support
TagsStoreTrait
A trait for types that can map between CBOR tags and their human-readable names.

Functions§

register_tags
register_tags_in
tags_for_values
Converts a slice of tag values to their corresponding Tag objects.

Type Aliases§

CBORSummarizer
A function type for summarizing CBOR values as human-readable strings.
Result
TagValue
Represents the numeric value of a CBOR tag.