Module Polymarket_ws.Frame

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

module Opcode : sig ... end

Close Status Codes

module Close_code : sig ... end

Frame Type

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

A WebSocket frame

Encoding/Decoding

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

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

val decode : _ Eio.Flow.source -> (t, string) Stdlib.result

Decode a frame from a flow. Blocks until a complete frame is received. Returns Error msg if the frame is too large or has invalid encoding.

Frame Constructors

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

Create a text frame.

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

Create a binary frame.

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

Create a ping frame.

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

Create a pong frame.

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

Create a close frame.

Masking

val apply_mask : key:string -> string -> string

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