lightpack/
lib.rs

1//! Lightpack is a lightweight, no-std binary serialization library that uses a
2//! simple, untagged encoding format. This makes it especially suitable for
3//! embedded use-cases.
4//! 
5//! The crate provides three core traits: [`Pack`] for encoding, [`Unpack`] for
6//! decoding and [`Size`] providing the encoded size in bytes as associated const.
7//! The first two traits are roughly analogouos to serde's `Serialize` and
8//! `Deserialize`.
9//! 
10//! These traits can be derived to make your own structures encodable and decodable:
11//! 
12//! ```ignore
13//! #[derive(Size, Pack, Unpack)]
14//! struct Point {
15//!     x: i16,
16//!     y: i16,
17//! }
18//! ```
19//! 
20//! To encode, call `pack` with an endianness (e.g. `lightpack::byteorder::BigEndian`) on a `&mut [u8]` slice:
21//! 
22//! ```ignore
23//! let mut buffer = [0u8; Point::SIZE];
24//! Point { x: 3, y: 4 }.pack::<BigEndian>(&mut buffer);
25//! // => buffer == [0, 3, 0, 4]
26//! ```
27//! 
28//! To decode, call `unpack` on a `&[u8]` slice:
29//! 
30//! ```ignore
31//! Point::unpack::<BigEndian>(&[0, 3, 0, 4]).unwrap()
32//! // => Point { x: 3, y: 4 }
33//! ```
34
35#![no_std]
36
37pub mod extra;
38pub mod pack;
39pub mod size;
40pub mod unpack;
41
42pub use pack::Pack;
43pub use size::Size;
44pub use unpack::Unpack;
45
46pub use byteorder;
47pub use lightpack_derive::*;