import { TPKT_HEADER_LEN, TPKT_VERSION } from './constants.js'; export function encodeTPKT(payload: Buffer): Buffer { const len = TPKT_HEADER_LEN + payload.length; const buf = Buffer.alloc(len); buf[0] = TPKT_VERSION; buf[1] = 0x00; buf.writeUInt16BE(len, 2); payload.copy(buf, TPKT_HEADER_LEN); return buf; } export function parseTPKTHeader(header: Buffer): { version: number; length: number } { return { version: header[0], length: header.readUInt16BE(2), }; } export function isValidTPKTHeader(header: Buffer): boolean { return header.length >= TPKT_HEADER_LEN && header[0] === TPKT_VERSION; }