Crate cbor_event

source ·
Expand description

CBOR event library

cbor_event is a minimalist CBOR implementation of the CBOR binary serialisation format. It provides a simple yet efficient way to parse CBOR without the need for an intermediate type representation.

Here is the list of supported CBOR primary Type:

  • Unsigned and Negative Integers;
  • Bytes and UTF8 String (finite length only);
  • Array and Map (of finite and indefinite size);
  • Tag;
  • Specials (bool, nullexcept floating points).

Raw deserialisation: Deserializer

Deserialisation works by consuming a Deserializer content. To avoid performance issues some objects use a reference to the original source Deserializer internal buffer. They are then linked to the object by an associated lifetime, this is true for Bytes.

use cbor_event::de::*;
use std::io::Cursor;

let vec = vec![0x43, 0x01, 0x02, 0x03];
let mut raw = Deserializer::from(Cursor::new(vec));
let bytes = raw.bytes().unwrap();

For convenience, we provide the trait Deserialize to help writing simpler deserializers for your types.

Serialisation: Serializer

To serialise your objects into CBOR we provide a simple object Serializer. It is configurable with any std::io::Write objects. Serializer is meant to be simple to use and to have limited overhead.

use cbor_event::se::{Serializer};

let mut serializer = Serializer::new_vec();
serializer.write_negative_integer(-12)
    .expect("write a negative integer");

Re-exports

pub use de::Deserialize;
pub use se::Serialize;

Modules

CBOR deserialisation tooling
CBOR serialisation tooling

Macros

macro to efficiently serialise the given structure into cbor binary.

Enums

all expected error for cbor parsing and serialising
CBOR len: either a fixed size or an indefinite length.
CBOR length with encoding details
CBOR Object key, represents the possible supported values for a CBOR key in a CBOR Map.
CBOR special (as in Special Primary Type).
Encoding for the length of a string (text or bytes)
How many bytes are used in CBOR encoding for a major type/length
CBOR Major Types
All possible CBOR supported values.

Functions

exported as a convenient function to test the implementation of Serialize and Deserialize.

Type Definitions

Result type for CBOR serialisation and deserialisation.