plushie/protocol/decode

Decode inbound wire messages into typed Gleam values.

Supports both MessagePack and JSON wire formats. The Rust binary sends three top-level message types: “hello” (handshake), “event” (user interaction dispatched by family), and “effect_response” (platform result). Additionally, “op_query_response” messages carry system query results.

Types

A decoded inbound message from the Rust binary.

pub type InboundMessage {
  Hello(
    protocol: Int,
    version: String,
    name: String,
    mode: String,
    backend: String,
    transport: String,
    native_widgets: List(String),
    widgets: List(String),
  )
  EventMessage(event.Event)
  EffectStubAck(kind: String)
  EffectResponseRaw(
    wire_id: String,
    status: String,
    payload: dynamic.Dynamic,
  )
  InteractStep(id: String, events: List(event.Event))
  InteractResponse(id: String, events: List(event.Event))
}

Constructors

  • Hello(
      protocol: Int,
      version: String,
      name: String,
      mode: String,
      backend: String,
      transport: String,
      native_widgets: List(String),
      widgets: List(String),
    )

    Handshake sent by the Rust binary on startup.

  • EventMessage(event.Event)

    A user interaction or system event.

  • EffectStubAck(kind: String)

    Acknowledgement that an effect stub was registered or unregistered.

  • EffectResponseRaw(
      wire_id: String,
      status: String,
      payload: dynamic.Dynamic,
    )

    Raw effect response from the renderer. Carries the wire ID (not the app-facing tag), the wire status string, and the dynamic payload. The runtime maps the wire ID to (tag, kind) and then decodes the typed EffectResult using the tracked kind.

  • InteractStep(id: String, events: List(event.Event))

    Intermediate step during an interact request. Contains events generated by the interaction that should be processed as a batch.

  • InteractResponse(id: String, events: List(event.Event))

    Final response to an interact request. Contains any remaining events to process.

Values

pub fn decode_from_dynamic(
  data: dynamic.Dynamic,
) -> Result(InboundMessage, protocol.DecodeError)

Decode an already-deserialized Dynamic value into an InboundMessage.

For use by test infrastructure that has already deserialized from wire format for multiplexing purposes but still needs to route through the production decoder rather than a parallel implementation.

pub fn decode_message(
  data: BitArray,
  format: protocol.Format,
) -> Result(InboundMessage, protocol.DecodeError)

Decode raw wire bytes into an InboundMessage.

Search Document