38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { type LocoPacketHeader, type LocoCommand } from "../types/index.js";
|
|
export declare function buildLocoPacket(id: number, command: LocoCommand, statusCode: number, body: Record<string, unknown>): Buffer;
|
|
export declare function parseLocoPacket(data: Buffer): {
|
|
header: LocoPacketHeader;
|
|
body: Record<string, unknown>;
|
|
} | null;
|
|
export declare function buildEncryptedPacket(locoPacket: Buffer, aesKey: Buffer): Buffer;
|
|
export declare function parseEncryptedPacket(data: Buffer, aesKey: Buffer): {
|
|
decrypted: Buffer;
|
|
consumed: number;
|
|
} | null;
|
|
export declare function buildHandshakePacket(aesKey: Buffer, serverPublicKeyPem: string): Buffer;
|
|
export declare function isHandshakePacket(data: Buffer): boolean;
|
|
/**
|
|
* In plaintext mode (over TLS), LOCO packets are sent raw — no length prefix.
|
|
* The packet itself contains bodyLength at offset 18, so we can frame it.
|
|
*/
|
|
export declare function buildPlainPacket(locoPacket: Buffer): Buffer;
|
|
export declare class PlainPacketReader {
|
|
private buffer;
|
|
/** Append incoming data and yield all complete parsed packets.
|
|
* Framing: read LOCO header (22 bytes), then bodyLength bytes. */
|
|
feed(chunk: Buffer): Array<{
|
|
header: LocoPacketHeader;
|
|
body: Record<string, unknown>;
|
|
}>;
|
|
}
|
|
export declare class PacketReader {
|
|
private buffer;
|
|
private aesKey;
|
|
constructor(aesKey: Buffer);
|
|
/** Append incoming data and yield all complete parsed packets. */
|
|
feed(chunk: Buffer): Array<{
|
|
header: LocoPacketHeader;
|
|
body: Record<string, unknown>;
|
|
}>;
|
|
}
|
|
//# sourceMappingURL=packet.d.ts.map
|