layline
Binary wire formats as Rust types.
Derive Layout for fixed-size records and Message for variable-length ones.
Fields must cover every bit, or the build fails. Encode fills in counts, lengths
and checksums; decode checks them.
[]
= "0.5"
Layouts
use Layout;
let header = decode;
assert_eq!;
assert_eq!;
A layout of up to 64 bits is shifts and masks on one integer. At 8, 16, 32 or 64 bits it also
converts to and from that integer: Header::from_bits(0x1A05) is the header above, read
big-endian. Add truncate to #[layout(..)] to have encode keep the low bits of an oversized
value, as a hardware register does, instead of panicking.
Add view to #[layout(..)] for <Name>View, which reads and writes fields in place. A view
reads any bytes, so a reader can inspect a corrupt record; verify() runs the checks decode
runs, checked(&wire) views only bytes that pass them, and seal() restamps magic bytes and
checksums after the setters.
In a bytes = N layout a bool is one byte that must be 0 or 1: decode refuses any other value.
A flag byte that any nonzero value sets is #[codec(8)] halted: layline::Nonzero.
Messages
use Message;
use Crc;
type Crc16 = ;
let frame = Frame ;
let wire = frame.encode;
assert_eq!;
let = decode.unwrap;
assert_eq!;
#[align(N)] after a #[len(n)] field adds zero padding up to a multiple of N bytes that n
does not count, as a RIFF chunk's odd body has.
A field can be present when a flag is clear: #[when(flags & 0x4 == 0)] or #[when(!flag)].
Encode writes the flag from the field, setting the bits for None.
A struct with a lifetime borrows its byte runs from the input instead of copying them, so it
decodes without an allocator. It implements MessageRef<'a>:
use ;
let wire = ;
let = decode.unwrap;
assert_eq!;
Switches
use ;
let = decode.unwrap;
assert_eq!;
Every attribute is documented on its derive.
Features
| Feature | Enables | Default |
|---|---|---|
derive |
The derive macros | Yes |
alloc |
Vec, String and Box fields |
Yes |
frame |
Stream framing | No |
num |
LEB128, Exp-Golomb and reserved values | No |
serde |
Serialize for U, I and Reserved |
No |
Crates
layline-core: theno_stdruntime, with no dependencies.layline-derive: the derive macros.layline-codegen: generates Rust source from a model, for formats defined outside Rust.
License
MPL-2.0