Sprites.Protocol (Sprites v0.1.0)
View SourceBinary protocol encoding/decoding for Sprites WebSocket.
Non-TTY Mode Protocol
Each message has a stream ID as the first byte:
- 0 - stdin (client -> server)
- 1 - stdout (server -> client)
- 2 - stderr (server -> client)
- 3 - exit (server -> client, first payload byte is the exit code; defaults to 0)
- 4 - stdin EOF (client -> server)
TTY Mode Protocol
- Binary frames are raw terminal data
- Text frames are JSON control messages
Summary
Functions
Decodes a binary message from the WebSocket.
Encodes stdin data for sending.
Encodes the stdin EOF signal.
Returns the stream ID constants.
Types
@type decoded() :: {stream_type(), binary() | integer() | nil}
@type stream_type() :: :stdin | :stdout | :stderr | :exit | :stdin_eof | :unknown
Functions
Decodes a binary message from the WebSocket.
Returns a tuple of {stream_type, payload} where:
{:stdout, binary}- stdout data{:stderr, binary}- stderr data{:exit, integer}- first payload byte as the exit code (defaults to 0 when omitted){:stdin_eof, nil}- stdin closed{:unknown, binary}- unrecognized data
Encodes stdin data for sending.
In TTY mode, data is sent as raw binary. In non-TTY mode, data is prefixed with the stdin stream ID.
@spec encode_stdin_eof() :: binary()
Encodes the stdin EOF signal.
Returns the stream ID constants.