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.23.2"§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.22.0"
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.21.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§
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. - Byte
String  - 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.
 - Diag
Format Opts  - HashMap
 - A hash map implemented with quadratic probing and SIMD lookup.
 - HashSet
 - A hash set implemented as a 
HashMapwhere the value is(). - HexFormat
Opts  - Lazy
Tags Store  - 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.
 - Tags
Store  - 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§
- CBOR
Case  - 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).
 - Tags
Store Opt  
Constants§
Statics§
Traits§
- CBOR
Codable  - A trait for types that can be both encoded to and decoded from CBOR.
 - CBOR
Decodable  - A trait for types that can be decoded from CBOR.
 - CBOR
Encodable  - CBOR Encoding and Decoding Traits
 - CBOR
Sortable  - CBOR
Tagged  - CBOR Tagged Value Support
 - CBOR
Tagged Codable  - Tagged CBOR Encoding and Decoding Support
 - CBOR
Tagged Decodable  - Tagged CBOR Decoding Support
 - CBOR
Tagged Encodable  - Tagged CBOR Encoding Support
 - Tags
Store Trait  - 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 
Tagobjects. 
Type Aliases§
- CBOR
Summarizer  - A function type for summarizing CBOR values as human-readable strings.
 - Result
 - TagValue
 - Represents the numeric value of a CBOR tag.