Skip to content

WebSocketFrameCodec

Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:48

RFC 6455 framing, for one end of a connection.

Decoding yields one WebSocketFrame per frame. A data frame’s payload is declared as the value’s body, so it is streamed rather than buffered — at most maxPayloadLength bytes, still masked when the frame carries a key (see createWebSocketMaskStream). A control frame’s payload, at most 125 bytes, comes inline and unmasked.

Every rule of §5.2 is checked: reserved opcodes, RSV bits no extension allows, masking against the role, fragmented or oversized control frames, a 64-bit length with its top bit set, and a length not in its shortest form. A violation is reported once as an error carrying a WebSocketFrameError, after which everything is discarded: the endpoint must send a close frame with its closeCode and close.

Encoding writes a header and the payload as two buffers for one vectored write. A server’s payload is passed through untouched; a client’s is masked with a fresh key from crypto.getRandomValues into a new buffer, so the caller’s bytes are never modified.

Message-level rules — continuation order, UTF-8 text — are the endpoint’s, since they span frames.

new WebSocketFrameCodec(options): WebSocketFrameCodec

Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:55

WebSocketFrameCodecOptions

WebSocketFrameCodec

decode(view): DecodeResult<WebSocketFrame>

Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:59

Attempt to decode one value from the front of view.

view is a window into the driver’s buffer and is invalidated as soon as this call returns. Copy anything retained in the returned value.

Uint8Array

DecodeResult<WebSocketFrame>

Codec.decode


encode(frame): readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:75

WebSocketOutboundFrame

readonly Uint8Array<ArrayBufferLike>[]

When a control frame is fragmented or carries more than 125 bytes, or rsv is not a 3-bit number.

Codec.encode


reset(): void

Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:119

Discard accumulated decode state ahead of a protocol mode switch.

void

Codec.reset