Union type and dispatcher for A2UI protocol messages.
Dispatches raw JSON maps to the appropriate message struct based on the message type key.
Summary
Functions
Parses a JSON string into a message struct.
Parses a decoded JSON map into the appropriate message struct.
Converts a message struct to a JSON string.
Converts a message struct to a JSON-compatible map.
Types
Functions
Parses a JSON string into a message struct.
Parses a decoded JSON map into the appropriate message struct.
Dispatches based on the presence of known message type keys.
Server→client messages must include "version": "v0.9".
Examples
iex> A2UI.Protocol.Message.from_map(%{"version" => "v0.9", "createSurface" => %{"surfaceId" => "main", "catalogId" => "test"}})
{:ok, %A2UI.Protocol.Messages.CreateSurface{surface_id: "main", catalog_id: "test"}}
@spec to_json(t()) :: {:ok, String.t()} | {:error, Jason.EncodeError.t()}
Converts a message struct to a JSON string.
Returns {:ok, json} or {:error, reason}.
Converts a message struct to a JSON-compatible map.
Server→client messages are wrapped with "version": "v0.9".
Action (client→server) is returned without a version wrapper.