Skip to main content

Crate mln_wire

Crate mln_wire 

Source
Expand description

Port-only: a compact binary encoding for the values that cross between wasm instances (mln_renderer’s tile/worker_codec).

A Wire type writes itself to a byte vector and reads itself from a Reader over a slice. Both are concrete, so each type compiles to one write function and one read function, without the visitors and error plumbing a serde format compiles for each type. The encoding is postcard’s: unsigned integers as LEB128 varints, signed ones zigzagged first, floats as their little-endian bytes, a sequence as its length and its items, an Option as a byte 0 or 1, a struct as its fields in order and an enum as its variant index and then its fields.

#[derive(Wire)] writes the impl for a struct or an enum (mln_wire_derive).

A value that needs more than its bytes to cross, such as the registry that a name resolves against, gets it from the Context that the writer or reader was made with.

Structs§

Error
Why a value couldn’t be read.
Reader
Reads values from the start of a slice, in a context, and keeps why one couldn’t be.
Request
A request for the part of a Context of one type.
Writer
Where values are written: bytes, the first value that couldn’t be, and the context they are written in.

Traits§

Context
What values need beyond their bytes to cross: the tables of the values that crossed before, the registry that names resolve against. A value asks its writer or reader for the part it needs by the part’s type (Writer::context, Reader::context).
Wire
A value that crosses between wasm instances.

Functions§

from_slice
The value that fills bytes.
from_slice_in
The value that fills bytes, read in context.
read_into
Reads a T into slot, dropping what it held. Not inlined, so that a struct of many fields (#[wire(default)]) calls it once per field rather than holding each field’s read, move and drop.
read_seq
Reads a sequence’s length and its items.
read_str
Reads a string, borrowed from the input.
to_vec
value encoded, or why it can’t be.
to_vec_in
value encoded in context, or why it can’t be.
write_seq
Writes a sequence’s length and its items.
write_str
Writes a string.
write_tag
Writes an enum’s variant index.
write_varint
Writes a varint.

Derive Macros§

Wire