[][src]Crate cbor_tools

cbor-tools is a toolkit for manipulating CBOR-encoded data.

CBOR is a data serialization format described in RFC7049. CBOR is a binary-friendly self-describing data encoding that has built-in types for:

  • Integers and Floating point numbers
  • Arrays and Maps
  • Arbitrary-length UTF-8 text strings
  • Arbitrary-length bytestrings

Other crates provide serde serialization and deserialization of native Rust data structures.

This crate provides tools for constructing CBOR with fine-grained control, including:

  • indefinite-length encoding
  • non-canonical encoding of integers
  • tagged types
  • sequences that may fail in strict-mode decoders
  • malformed sequences (for testing decoders, perhaps)

To encode some data in CBOR, create one or more CborType values, and then call encode() on them:

use cbor_tools::{CborType, Encode};

let my_data = vec![1, 2, 3];
let cbor_tree = CborType::from(my_data);
let cbor_bytes = cbor_tree.encode();
// cbor_bytes is a Vec<u8>

There is a From<T> implementation available for many simple types. Additional data structures can be built by hand, like this non-homogenous array:

use cbor_tools::{CborType, Encode};

// An array containing a string and an integer.
let list = vec![
    CborType::from("abc"),
    CborType::from(123),
];
let cbor_tree = CborType::from(list);
let cbor_bytes = cbor_tree.encode();
// cbor_bytes is a Vec<u8>

Modules

format

Specifies the exact binary format of CBOR data.

Structs

Array

An array of values.

ByteString

A byte string.

IntOverflowError

The integer value was too large to be represented as a CBOR integer.

Map

An map of (key, value) pairs.

Tag

A tag value for use with Tagged

Tagged

A tagged value.

TextString

A UTF-8 text string.

ZeroTo23

An integer value in the range 0 to 23, inclusive.

Enums

CborType

A CBOR value.

Float

A floating-point value.

Indefinite

Indefinite-length bytestrings, textstrings, arrays, and maps.

Integer

CBOR Integer type

Traits

Encode

Binary CBOR encoding.

EncodeSymbolic

Symbolic CBOR encoding.