lightspeed/protocol

Versioned protocol frame model.

Types

Protocol decode errors.

pub type DecodeError {
  EmptyFrame
  UnknownFrameTag(String)
  BadFieldCount(tag: String, expected: Int, actual: Int)
  InvalidVersion(String)
  UnsupportedVersion(Int)
  UnsupportedProtocol(String)
  InvalidEscapeSequence
}

Constructors

  • EmptyFrame
  • UnknownFrameTag(String)
  • BadFieldCount(tag: String, expected: Int, actual: Int)
  • InvalidVersion(String)
  • UnsupportedVersion(Int)
  • UnsupportedProtocol(String)
  • InvalidEscapeSequence

Protocol frame exchanged between client and server.

pub type Frame {
  Hello(protocol: String, version: Int)
  Event(ref: String, name: String, payload: String)
  Diff(ref: String, html: String)
  Ack(ref: String)
  Failure(ref: String, reason: String)
}

Constructors

  • Hello(protocol: String, version: Int)
  • Event(ref: String, name: String, payload: String)
  • Diff(ref: String, html: String)
  • Ack(ref: String)
  • Failure(ref: String, reason: String)

Values

pub fn decode(payload: String) -> Result(Frame, DecodeError)

Decode a textual frame payload.

pub fn decode_error_to_string(error: DecodeError) -> String

Convert decode errors to stable strings for logs and adapter errors.

pub fn encode(frame: Frame) -> String

Encode a frame into a transport-safe textual format.

pub fn hello() -> Frame

Construct a protocol hello frame.

pub fn is_current_hello(frame: Frame) -> Bool

True when the frame is part of the current protocol.

pub const protocol_name: String
pub const protocol_version: Int
pub fn ref(frame: Frame) -> String

Return the frame reference when one exists.

Search Document