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.
Implements
Section titled “Implements”Codec<WebSocketFrame,WebSocketOutboundFrame>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WebSocketFrameCodec(
options):WebSocketFrameCodec
Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:55
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”WebSocketFrameCodec
Methods
Section titled “Methods”decode()
Section titled “decode()”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.
Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”DecodeResult<WebSocketFrame>
Implementation of
Section titled “Implementation of”Codec.decode
encode()
Section titled “encode()”encode(
frame): readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:75
Parameters
Section titled “Parameters”Returns
Section titled “Returns”readonly Uint8Array<ArrayBufferLike>[]
Throws
Section titled “Throws”When a control frame is fragmented or carries more
than 125 bytes, or rsv is not a 3-bit number.
Implementation of
Section titled “Implementation of”Codec.encode
reset()
Section titled “reset()”reset():
void
Defined in: packages/format-websocket/src/frame/websocket-frame-codec.ts:119
Discard accumulated decode state ahead of a protocol mode switch.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Codec.reset