/** * Minimal RFC 6455 frame codec used by the gateway's native (Bun) WebSocket * upgrade relay. * * The gateway only needs it on runtimes whose HTTP server cannot hand the raw * upgraded socket back to JavaScript (see `BunNativeUpgradeRelay`): there the * client side is a native WebSocket (message level), while the upstream side is * a raw socket, so frames have to be decoded/encoded in between. * * The codec deliberately implements a single, predictable flavour of the * protocol: no extensions (the relay never offers `permessage-deflate`), no * fragmentation on the outbound path (one frame per message) and a bounded * inbound message size. */ export declare const WS_OPCODE: { readonly continuation: 0; readonly text: 1; readonly binary: 2; readonly close: 8; readonly ping: 9; readonly pong: 10; }; export type WebSocketFrameOpcode = typeof WS_OPCODE[keyof typeof WS_OPCODE]; /** Close code used when the peer violates the protocol. */ export declare const WS_CLOSE_PROTOCOL_ERROR = 1002; /** Close code used when a message exceeds the configured size limit. */ export declare const WS_CLOSE_MESSAGE_TOO_BIG = 1009; export interface EncodeWebSocketFrameOptions { opcode: WebSocketFrameOpcode; /** Client-to-server frames must be masked; server-to-client frames must not. */ mask: boolean; /** Deterministic mask key, for tests only. */ maskKey?: Buffer; } export declare function encodeWebSocketFrame(payload: Buffer, options: EncodeWebSocketFrameOptions): Buffer; /** Encodes a close frame body (`code` + UTF-8 reason). */ export declare function encodeWebSocketClosePayload(code: number, reason: string): Buffer; export interface WebSocketFrameSink { /** A complete (possibly reassembled) data message. */ onMessage(payload: Buffer, isBinary: boolean): void; onPing(payload: Buffer): void; onPong(payload: Buffer): void; onClose(code: number, reason: string): void; /** The peer sent something that violates the protocol; the connection should be closed with 1002. */ onProtocolError(reason: string): void; } export interface WebSocketFrameParserOptions { /** Upper bound for a single (reassembled) message; oversized messages raise a protocol error. */ maxMessageBytes?: number; } export declare class WebSocketFrameParser { private readonly sink; private buffer; private fragmentOpcode; private fragments; private fragmentBytes; private failed; private readonly maxMessageBytes; constructor(sink: WebSocketFrameSink, options?: WebSocketFrameParserOptions); push(chunk: Buffer): void; private fail; /** @returns whether a complete frame was consumed. */ private parseFrame; private handleFrame; private appendFragment; private completeMessage; }