Skip to main content

Crate zerec

Crate zerec 

Source
Expand description

§zerec

Minimal zero-copy binary codec for Rust.

  • No schema files. Types are the schema.
  • No runtime reflection. Everything is resolved at compile time.
  • No type tags on the wire. You know what you are decoding into.
  • Little-endian, tightly packed. No padding, no alignment waste.

§Quick start

[dependencies]
zerec = { version = "0.3", features = ["derive"] }
use zerec::{Encode, Decode, codec::{to_bytes, from_bytes}};

#[derive(Encode, Decode, Debug, PartialEq)]
struct Bullet {
    origin: [f32; 3],
    speed:  f32,
    damage: u32,
}

let b = Bullet { origin: [1.0, 0.0, -3.5], speed: 900.0, damage: 42 };
let bytes = to_bytes(&b);
assert_eq!(from_bytes::<Bullet>(&bytes).unwrap(), b);

§Wire format

ZRC is tag-free and little-endian. See the crate-level docs or README for the full encoding table.

§Features

FeatureWhat it enables
derive#[derive(Encode, Decode)] via zerec-derive
glamEncode/Decode for glam::Vec2/3/4, Quat, Mat4

Re-exports§

pub use adapter::Adapter;
pub use codec::Decode;
pub use codec::Encode;
pub use error::DecodeError;
pub use zero_copy::ZeroBuf;

Modules§

adapter
Adapter pattern for foreign types.
codec
Core Encode and Decode traits, plus top-level convenience functions.
decoder
Read-side of the ZRC wire format.
encoder
Write-side of the ZRC wire format.
error
Decode-time error types.
impls
integrations
zero_copy
Zero-copy borrowing from the source buffer.