Expand description
The byte codec both surfaces share. One writer, one reader — the host links these functions and so does every guest, so a field cannot be encoded one way and decoded another (LAW 5, by construction rather than by a guard watching two copies agree).
§Why not JSON
znippy’s wasm_loader::parse_json_to_row splits on , and : before
stripping quotes, so a value containing either separator silently corrupts
the row, and it has no null representation at all — an absent column and an
empty one are the same bytes on the wire. Both are properties of the ad-hoc
format, not bugs that can be patched out of the parser.
This codec is length-prefixed, so a value is copied by length and its
contents are never scanned for structure: ,, :, ", a NUL and an
arbitrary UTF-8 sequence all survive a round trip. Option carries an
explicit 1-byte tag, so None and Some("") are distinct on the wire.
codec_tests.rs asserts exactly those two properties.
§Layout
| type | bytes |
|---|---|
u32 / u16 / u64 / i64 | little-endian, fixed width |
bool | 1 byte, 0 or 1 |
bytes / String | u32 length, then that many bytes |
Option<T> | 0u8, or 1u8 then T |
Vec<T> | u32 count, then that many T |
Result<T, String> | 0u8 then T, or 1u8 then the message |
Structs§
Enums§
- Decode
Error - Why a byte string could not be decoded. Every variant names the field being read, because a decode failure on the host side is otherwise indistinguishable from a plugin that returned nothing.
Functions§
- read_
result - Decode a
Result<T, String>written bywrite_result. - write_
result - Encode a
Result<T, String>: tag0= ok, tag1= the error message.