Skip to content

encodeHeaderInto

encodeHeaderInto(buffer, header): void

Defined in: packages/protocol/src/wire-format.ts:165

Encode a frame header INTO an existing buffer (zero allocation).

Use this with a pre-allocated buffer to avoid allocation overhead in high-throughput scenarios (e.g., ring buffer pattern).

Buffer

Target buffer (must be at least HEADER_SIZE bytes)

FrameHeader

Header to encode

void

const headerBuf = Buffer.allocUnsafe(HEADER_SIZE);
encodeHeaderInto(headerBuf, {
methodId: 1,
flags: 0,
requestId: 42,
payloadLength: 1024,
});
socket.write(headerBuf);