lightpack

Crates.iolightpack
lib.rslightpack
version0.2.8
sourcesrc
created_at2023-08-02 20:55:28.21059
updated_at2023-08-24 16:39:49.708769
descriptionA lightweight, no-std binary serialization library
homepagehttps://github.com/ProjectLighthouseCAU/lightpack
repositoryhttps://github.com/ProjectLighthouseCAU/lightpack
max_upload_size
id933095
size42,126
dev (github:projectlighthousecau:dev)

documentation

README

Lightpack

crates.io Build docs.rs

A lighweight, no-std binary serialization library.

Example

Lightpack provides derivable traits for encoding (Pack) and decoding (Unpack), as well as for determining a type's encoded size (Size):

#[derive(Size, Pack, Unpack, Debug)]
struct Point {
    x: i16,
    y: i16,
}

To encode, call pack with an endianness (e.g. lightpack::byteorder::BigEndian) on a &mut [u8] slice:

let mut buffer = [0u8; Point::SIZE];
Point { x: 3, y: 4 }.pack::<BigEndian>(&mut buffer);
// => buffer == [0, 3, 0, 4]

To decode, call unpack on a &[u8] slice:

Point::unpack::<BigEndian>(&[0, 3, 0, 4]).unwrap()
// => Point { x: 3, y: 4 }

For a complete example, check out examples/point.rs.

Commit count: 86

cargo fmt