Module Websocket.FrameSource

WebSocket frame encoding and decoding (RFC 6455).

This module implements the binary frame format for WebSocket messages. Client frames must be masked; server frames are unmasked.

Frame Opcodes

Sourcemodule Opcode : sig ... end

Close Status Codes

Sourcemodule Close_code : sig ... end

Frame Type

Sourcetype t = {
  1. fin : bool;
  2. opcode : Opcode.t;
  3. payload : string;
}

A WebSocket frame

Encoding/Decoding

Sourceval encode : mask:bool -> t -> string

Encode a frame for sending. Client frames should use mask:true.

Sourceval decode : _ Eio.Flow.source -> t

Decode a frame from a flow. Blocks until a complete frame is received.

Frame Constructors

Sourceval text : ?fin:bool -> string -> t

Create a text frame.

Sourceval binary : ?fin:bool -> string -> t

Create a binary frame.

Sourceval ping : ?payload:string -> unit -> t

Create a ping frame.

Sourceval pong : ?payload:string -> unit -> t

Create a pong frame.

Sourceval close : ?code:Close_code.t -> ?reason:string -> unit -> t

Create a close frame.

Masking

Sourceval apply_mask : key:string -> string -> string

Apply XOR mask to a payload. Used for client-to-server message masking.