Data Flow
The core’s rendering pipeline produces a ZRDL binary every frame. The engine parses that binary, executes the draw commands against the terminal, and sends back input events as ZREV batches.Binary Format Principles
All Rezi binary formats share the following properties:- Little-endian byte order. All multi-byte integers are stored least-significant byte first.
- 4-byte alignment. All section offsets, section sizes, and the total buffer size are 4-byte aligned. Padding bytes are explicitly zeroed.
- Versioned. Each format begins with a magic number and version field. The engine rejects unknown versions.
- Validated strictly. Both the builder (TypeScript side) and the engine (C side) validate the buffer independently. Malformed input is never silently accepted.
Format Summary
| Format | Magic bytes | Description | Direction | |--------|-------------|-------------|-----------|| | ZRDL |0x4C44525A (ZRDL) | Drawlist: rendering commands, strings, blobs | Core → Engine |
| ZREV | 0x5645525A (ZREV) | Event batch: keyboard/mouse/resize events | Engine → Core |
Both magic values are encoded as little-endian u32 constants.
Magic Bytes
ZRDL Drawlists
Purpose: Encode rendering commands from TypeScript to native engine Structure:- 64-byte header with section offsets
- Command stream (fixed-size command records)
- String span table + byte pool
- Blob span table + byte pool
OP_CLEAR— clear framebufferOP_FILL_RECT— fill rectangle with styleOP_DRAW_TEXT— draw UTF-8 stringOP_PUSH_CLIP/OP_POP_CLIP— clipping regionsOP_SET_CURSOR— terminal cursor control (v2+)OP_DRAW_TEXT_RUN— multi-segment styled textOP_DRAW_CANVAS— canvas rendering (v4+)OP_DRAW_IMAGE— image rendering (v5+)
ZREV Event Batches
Purpose: Encode input events from native engine to TypeScript Structure:- 24-byte header with version and record count
- Self-framed event records (variable length)
- Key — keyboard input with key code and modifiers
- Mouse — mouse events (move, drag, down, up, wheel)
- Resize — terminal size change
- Tick — animation frame timer
Versioning Strategy
Rezi uses explicit version pins at every binary boundary.Engine ABI Version
Tracks the C engine’s public API surface:1.2.0
Compatibility rules:
- Major mismatch → incompatible
- Minor mismatch → backward compatible if
core.minor <= engine.minor - Patch mismatch → always compatible
Drawlist Format Versions
- v1: Base format (CLEAR, FILL_RECT, DRAW_TEXT, PUSH_CLIP, POP_CLIP, DRAW_TEXT_RUN)
- v2: Adds SET_CURSOR for native cursor control
- v3: Extends style payloads (underline style/color + hyperlink refs)
- v4: Adds DRAW_CANVAS
- v5: Adds DRAW_IMAGE
Event Batch Version
1
See: Protocol Versioning
Unicode Version Pin
Rezi pins Unicode 15.1.0 for deterministic text measurement:Validation Flow
Builder Side (TypeScript)
- Builder writes correct magic and version into header
- Builder validates all commands before writing
- Builder enforces resource caps (strings, blobs, total bytes)
build()returns{ ok: true, bytes }or{ ok: false, error }
Engine Side (C)
- Read magic at offset 0. Reject with
ERR_FORMATif mismatch - Read version at offset 4. Reject with
ERR_UNSUPPORTEDif unknown - Validate header size at offset 8. Reject if wrong
- Process commands. Reject unknown opcodes with
ERR_UNSUPPORTED - Validate section offsets and alignment
- Execute commands against framebuffer
Safety Guarantees
All binary protocols enforce:- Validate before read. Every field is bounds-checked before access
- Cap enforcement. All resource pools have configurable upper bounds
- Structured error returns. Parsers never throw into user code
- Alignment invariants. All offsets/sizes are 4-byte aligned
- Deterministic failure. Same invalid input → same error
ABI Constants
All version constants and magic bytes are exported from@rezi-ui/core:
Related Documentation
- ZRDL Drawlists — Rendering command format
- ZREV Event Batches — Input event format
- Versioning — Version compatibility rules
- Safety Rules — Validation patterns
- ABI Pins — Constant reference table