Skip to main content

Module buffer

Module buffer 

Source
Expand description

The WeaveFFI value-buffer protocol: the by-value serialization format records, rich enums, optionals, lists, maps, and error payloads use to cross the C ABI.

A buffered value crosses the boundary as one (const uint8_t*, size_t) slot pair containing the value serialized in this module’s format, rather than as an opaque object pointer or parallel arrays. Parameters are borrowed for the duration of the call (the consumer owns and frees its own encoding); returns are producer-allocated and released by the consumer with weaveffi_free_bytes after decoding.

§Encoding

All multi-byte values are little-endian. There is no padding and no alignment; values are packed back to back.

IDL typeEncoding
bool1 byte: 0 or 1
i8/u81 byte
i16/u162 bytes
i32/u324 bytes
i64/u648 bytes
f324 bytes (IEEE 754 bits)
f648 bytes (IEEE 754 bits)
enum (C-style)i32 discriminant
interfaceu64 object token carrying one strong reference
stringu32 byte length + UTF-8 bytes (no NUL terminator)
bytesu32 length + raw bytes
T?1 byte flag (0 absent, 1 present) + value
[T]u32 count + each element
{K:V}u32 count + alternating key, value
recordeach field in declaration order
rich enumi32 tag + active variant’s fields in order
error payloadthe matched code’s fields in declaration order

Because the format is compositional, arbitrary nesting ({string:[T?]}, records containing records, objects inside lists, and so on) works with no per-shape special cases. Iterators and callback interfaces never appear inside a buffer; validation rejects them in buffered positions.

An interface object is encoded as a token (see object) that carries one strong reference: the writer clones the object before encoding and the reader adopts the reference. Because adopting is a side effect, a buffer holding object tokens must be decoded exactly once.

Encoded lengths and counts are u32, capping any single string, byte buffer, or collection at u32::MAX entries; BufferWriter panics past that bound rather than truncating.

Structs§

BufferDecodeError
An error produced while decoding a value buffer.
BufferReader
Decodes values from the WeaveFFI buffer format.
BufferWriter
Serializes values into the WeaveFFI buffer format.

Traits§

BufferValue
A value that can serialize itself into (and decode itself from) the WeaveFFI buffer format.

Functions§

decode_value
Decode one BufferValue from an encoded buffer, requiring the buffer to be fully consumed.
encode_value
Encode one BufferValue into a fresh byte buffer.