1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#![doc(html_root_url = "https://docs.rs/dcbor/0.13.2")]
#![warn(rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
//! # dCBOR: Deterministic CBOR Codec
//!
//! `dcbor` is a [CBOR](https://cbor.io) codec that focuses on writing and
//! parsing "deterministic" CBOR per [§4.2 of
//! RFC-8949](https://www.rfc-editor.org/rfc/rfc8949.html#name-deterministically-encoded-c).
//! 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 return 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`:
//!
//! ```toml
//! [dependencies]
//! dcbor = "0.13.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`:
//!
//! ```toml
//! [dependencies.dcbor]
//! version = "0.13.2"
//! 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:
//!
//! ```toml
//! [dependencies.dcbor]
//! version = "0.13.2"
//! default-features = false
//! features = ["no_std"]
//! ```
//!
//! # Specification
//!
//! 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](https://datatracker.ietf.org/doc/draft-mcnally-deterministic-cbor/).
//!
//! # Usage
//!
//! Encode an array of integers as CBOR.
//!
//! ```
//! # fn main() {
//! # {
//! use dcbor::prelude::*;
//! let array = [1000, 2000, 3000];
//! let cbor = array.cbor();
//! assert_eq!(cbor.hex(), "831903e81907d0190bb8");
//! # }
//! # }
//! ```
//!
//! Decode CBOR binary back to an array of integers.
//!
//! ```
//! # fn main() {
//! # {
//! use dcbor::prelude::*;
//! let data = hex_literal::hex!("831903e81907d0190bb8");
//! let cbor = CBOR::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.
#[macro_use]
mod stdlib;
mod cbor;
pub use cbor::*;
mod bytes;
mod bool_value;
mod float;
mod array;
mod error;
pub use error::CBORError;
mod date;
pub use date::Date;
mod diag;
mod dump;
mod tags_store;
pub use tags_store::{TagsStoreTrait, TagsStore};
mod tag;
pub use tag::Tag;
mod cbor_encodable;
pub use cbor_encodable::CBOREncodable;
mod cbor_decodable;
pub use cbor_decodable::CBORDecodable;
mod cbor_codable;
pub use cbor_codable::CBORCodable;
mod cbor_tagged;
pub use cbor_tagged::CBORTagged;
mod cbor_tagged_encodable;
pub use cbor_tagged_encodable::CBORTaggedEncodable;
mod cbor_tagged_decodable;
pub use cbor_tagged_decodable::CBORTaggedDecodable;
mod cbor_tagged_codable;
pub use cbor_tagged_codable::CBORTaggedCodable;
mod decode;
mod int;
mod map;
pub use map::{Map, MapIter};
mod string;
mod string_util;
mod simple;
pub use simple::Simple;
mod varint;
mod exact;
use exact::ExactFrom;
pub mod prelude;