plushie/protocol/encode
Encode outbound messages for the plushie wire protocol.
Each function encodes a specific message type to wire format (JSONL or MessagePack bytes). All outbound messages include a “type” field identifying the message kind and a “session” field for multiplexed session support.
Values
pub fn encode_advance_frame(
timestamp: Int,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a frame advance (test/headless mode).
pub fn encode_command(
id: String,
family: String,
value: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a widget-targeted command using the unified format. Wire: {type: “command”, session, id, family, value}
pub fn encode_commands(
commands: List(
#(String, String, dict.Dict(String, node.PropValue)),
),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a batch of widget-targeted commands. Wire: {type: “commands”, session, commands: [{id, family, value}, …]}
pub fn encode_effect(
id: String,
kind: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a platform effect request (file dialog, clipboard, etc.).
pub fn encode_image_op(
op: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an image operation (create_image, update_image, delete_image).
Uses the unified _op envelope: op-specific data (including handle,
data, pixels, width, height) lives under payload.
pub fn encode_interact(
id: String,
action: String,
selector: dict.Dict(String, node.PropValue),
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an interact request (click, type_text, press, etc.).
Used by the scripting engine and testing infrastructure to perform renderer-side interactions on the widget tree.
pub fn encode_load_font(
family: String,
data: BitArray,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a load_font message.
data carries the font bytes. JSON encodes them as a base64 string;
MessagePack encodes them as a native binary value. BinaryVal handles
both representations.
pub fn encode_patch(
ops: List(patch.PatchOp),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an incremental patch (list of diff operations).
pub fn encode_register_effect_stub(
kind: String,
response: node.PropValue,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an effect stub registration.
The renderer will return the given response value immediately for any effect of this kind, without executing the real effect.
pub fn encode_settings(
settings: app.Settings,
session: String,
format: protocol.Format,
token: option.Option(String),
) -> Result(BitArray, protocol.EncodeError)
Encode a settings message sent on startup.
Settings are wrapped in a "settings" key in the wire message,
matching the Rust binary’s expected format:
{"type": "settings", "session": "", "settings": {...}}
pub fn encode_snapshot(
tree: node.Node,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a full tree snapshot.
pub fn encode_subscribe(
kind: String,
tag: String,
max_rate: option.Option(Int),
window_id: option.Option(String),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a subscribe message to start an event source.
pub fn encode_system_op(
op: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a system-wide operation.
Uses the unified _op envelope: op-specific data lives under payload.
pub fn encode_system_query(
op: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a system-wide query.
Uses the unified _op envelope: query-specific data lives under payload.
pub fn encode_unregister_effect_stub(
kind: String,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an effect stub removal.
pub fn encode_unsubscribe(
kind: String,
tag: String,
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode an unsubscribe message to stop an event source. Includes the tag for targeted unsubscription when multiple subscriptions of the same kind exist (e.g. window-scoped).
pub fn encode_widget_op(
op: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a global widget operation (no target ID: focus_next, announce, etc.).
pub fn encode_window_op(
op: String,
window_id: String,
payload: dict.Dict(String, node.PropValue),
session: String,
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Encode a window operation (open, close, configure).
Uses the unified _op envelope: op-specific data lives under
payload; the window_id addressing field stays flat beside op.
pub fn node_to_prop_value(n: node.Node) -> node.PropValue
Convert a Node tree to a nested PropValue (DictVal).
Maps kind to the wire key "type".
pub fn patch_op_to_prop_value(
op: patch.PatchOp,
) -> node.PropValue
Convert a PatchOp to its wire PropValue representation.
Paths are encoded as arrays of integers on the wire.
pub fn prop_value_to_json(v: node.PropValue) -> json.Json
Convert a PropValue to gleam_json’s Json type.
pub fn prop_value_to_msgpack(v: node.PropValue) -> data.Value
Convert a PropValue to glepack’s data.Value type.
pub fn serialize(
message: dict.Dict(String, node.PropValue),
format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)
Serialize a message (represented as a Dict of PropValues) to wire bytes. JSON format appends a newline; MessagePack produces raw bytes.