VireoRPC v2.4 Wire Protocol Specification

Document status: Normative specification for VireoRPC binary stream framing over WebAssembly (WASI Preview 2 and browser linear memory).

1. Frame Structure

Every VireoRPC message transmitted across a WebAssembly host-guest boundary MUST be encapsulated in a length-prefixed varint frame. Implementations MUST encode the payload byte length as an unsigned LEB128 varint header followed by a 1-byte flags field and the raw payload bytes.

+-------------------+---------------+---------------------------+
| Length (LEB128)   | Flags (1 B)   | Payload Bytes (0..N B)    |
+-------------------+---------------+---------------------------+

2. Payload Limits and Overflow Handling

The default maximum frame size is 64 KB (65,536 bytes) per single-shot RPC call unless negotiated upward during the handshake. If a sender attempts to serialize a frame exceeding the negotiated ceiling, the encoder MUST abort serialization immediately and return error code ERR_FRAME_CAP_104 without advancing the stream cursor. Receivers encountering an oversized header MUST close the logical channel with ERR_FRAME_CAP_104.

3. Reference Encoding Performance

On the reference Wasmtime 28 runtime (x86_64, single-threaded linear memory copy), the VireoRPC v2.4 reference encoder achieves a p99 encode latency of 0.42 ms on 64 KB payloads and a p50 latency of 0.14 ms. Zero-copy slice views SHOULD be used when the host allocates shared ring buffers, avoiding secondary heap allocations during streaming bursts.

4. Stream Multiplexing

Flags bit 0 signals continuation frames for payloads split across multiple 64 KB chunks. Flags bit 1 indicates end-of-stream. Conformant decoders MUST validate the varint length before copying bytes into guest memory to prevent out-of-bounds traps. Checksum trailers are optional in v2.4 and disabled by default on trusted intra-process Wasm pipes.