Skip to main content

Crate neopack

Crate neopack 

Source
Expand description

Neopack is a small binary serialization library.

Everything is encoded using a (nestable!) tag-length-value (TLV) format. A one-byte tag says what follows, an optional four-byte length says how big it is, then the value data follows. All integers are little-endian.

(Some notes for writing neopack encoders/decoders for your types by hand.) Encoding is explicit, you push values onto an Encoder, then call Encoder::into_bytes. Decoding is zero-copy, a Decoder borrows the input slice and hands back references.

Thankfully, for structs and enums, #[derive(Pack, Unpack)] (via neopack-derive) generates neopack implementations automatically.

use neopack::Pack;
use neopack::Unpack;

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

let bytes = Point { x: 1, y: 2 }.pack_to_vec().unwrap();
let point = Point::unpack_from_bytes(&bytes).unwrap();

Structs§

Decoder
A zero-copy, bounds-checked cursor over a byte slice.
Encoder
A bounded, state-machine driven encoder.
ListIter
Iterator for items within a List.
MapIter
Iterator for Key-Value pairs (Variants) within a Map.
SchemaField
A named field used in SchemaType::Struct and SchemaType::Enum.

Enums§

Error
Neopack serialization and deserialization errors.
SchemaType
Describes the shape of a neopack value.
Scope
Internal state tracking for the Encoder stack.
Tag
Identifies the type of the encoded value.

Traits§

Pack
Encode a value into a neopack byte stream.
Schema
Returns the SchemaType describing a type’s neopack encoding.
Unpack
Decode a value from a neopack byte stream.

Functions§

lower
Compile text to neopack bytes, guided by a schema.
raise
Decompile neopack bytes to text, guided by a schema.

Type Aliases§

Result
Specialized Result for Neopack operations.

Derive Macros§

Pack
Schema
Unpack