Sprites.Protocol (Sprites v0.2.0)

View Source

Binary 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

decoded()

@type decoded() :: {stream_type(), binary() | integer() | nil}

stream_type()

@type stream_type() :: :stdin | :stdout | :stderr | :exit | :stdin_eof | :unknown

Functions

decode(data)

@spec decode(binary()) :: decoded()

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

encode_stdin(data, bool)

@spec encode_stdin(iodata(), boolean()) :: binary()

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.

encode_stdin_eof()

@spec encode_stdin_eof() :: binary()

Encodes the stdin EOF signal.

exit_id()

stderr_id()

stdin_eof_id()

stdin_id()

Returns the stream ID constants.

stdout_id()