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
,null
… except 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
Macros
Enums
Functions
Serialize
and
Deserialize
.Type Definitions
Result
type for CBOR serialisation and deserialisation.