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§

de
CBOR deserialisation tooling
se
CBOR serialisation tooling

Macros§

cbor
macro to efficiently serialise the given structure into cbor binary.

Enums§

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

Functions§

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

Type Aliases§

Result
Result type for CBOR serialisation and deserialisation.