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_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_extension_command(
  node_id: String,
  op: String,
  payload: dict.Dict(String, node.PropValue),
  session: String,
  format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)

Encode an extension command for custom widget operations.

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).

Payload fields are flat-merged into the top-level message dict (not nested under “payload”), matching the Elixir reference.

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_settings(
  settings: app.Settings,
  session: String,
  format: protocol.Format,
) -> 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),
  session: String,
  format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)

Encode a subscribe message to start an event source.

pub fn encode_unsubscribe(
  kind: String,
  session: String,
  format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)

Encode an unsubscribe message to stop an event source.

pub fn encode_widget_op(
  op: String,
  payload: dict.Dict(String, node.PropValue),
  session: String,
  format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)

Encode a widget operation (focus, scroll, etc.).

pub fn encode_window_op(
  op: String,
  window_id: String,
  settings: dict.Dict(String, node.PropValue),
  session: String,
  format: protocol.Format,
) -> Result(BitArray, protocol.EncodeError)

Encode a window operation (open, close, configure).

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.

Search Document