simvx.graphics.streaming.draw_serializer

Binary serialization of Draw2D batches for WebSocket streaming.

Serializes the output of Draw2D._get_batches() into compact binary frames for transmission to a browser-side WebGPU 2D renderer.

Wire format per frame::

Header:  frame_id(u32) + batch_count(u32) + atlas_version(u32)   [12 bytes]
Per batch:
    clip_rect(4×f32)                                              [16 bytes]
    sub-batches (variable), terminated by 0xFF sentinel byte
Per sub-batch:
    draw_type(u8) + vertex_count(u32) + index_count(u32)         [9 bytes]
    raw vertex bytes (vertex_count × 32)
    raw index bytes  (index_count × 4)

Draw types: 0=fill, 1=line, 2=text, 3=textured (textured adds texture_id u32 before vertices).

Module Contents

Classes

DrawSerializer

Serializes Draw2D batch output into binary frames for WebSocket streaming.

Data

API

simvx.graphics.streaming.draw_serializer.__all__

[‘DrawSerializer’]

simvx.graphics.streaming.draw_serializer.DRAW_FILL

0

simvx.graphics.streaming.draw_serializer.DRAW_LINE

1

simvx.graphics.streaming.draw_serializer.DRAW_TEXT

2

simvx.graphics.streaming.draw_serializer.DRAW_TEXTURED

3

simvx.graphics.streaming.draw_serializer.BATCH_END

255

class simvx.graphics.streaming.draw_serializer.DrawSerializer[source]

Serializes Draw2D batch output into binary frames for WebSocket streaming.

static serialize_frame(frame_id: int, batches: list, atlas_version: int = 0) bytes[source]

Serialize a list of Draw2D batches into a binary frame.

Args: frame_id: Monotonic frame counter. batches: Output of Draw2D._get_batches() — list of (clip, fill_data, line_data, text_data, tex_draws). atlas_version: Current MSDF atlas version for cache invalidation.

Returns: Compact binary frame ready for WebSocket transmission.

static deserialize_frame(data: bytes) dict[str, Any][source]

Deserialize a binary frame back into structured data (for testing).

Returns: Dict with keys: frame_id, atlas_version, batches. Each batch: dict with clip, sub_batches list. Each sub_batch: dict with draw_type, vertices, indices, texture_id (optional).