/** * The realtime-events action header. Every action frame is a JSON object carrying at least these four string fields; controllers may include arbitrary additional * keys, which are preserved on the index signature. The decoder validates this shape, so a {@link RawPacket}'s `header` is always trustworthy downstream. */ export interface ProtectEventHeader { action: string; id: string; modelKey: string; newUpdateId: string; [key: string]: boolean | number | object | string; } /** * The decoded, still-untyped form of a realtime-events packet: the validated action {@link ProtectEventHeader} and the raw data-frame payload. The payload is * `unknown` because the data frame may be parsed JSON (the dominant case), a UTF-8 string, or a raw `Buffer`; interpreting it is the classifier's job, not the codec's. * It is the element type of the raw firehose (`client.rawPackets()`) and the input/output of the static `ProtectClient.decodePacket` / `ProtectClient.classifyPacket`. */ export interface RawPacket { header: ProtectEventHeader; payload: unknown; } /** * Decode a realtime-events packet from its on-the-wire bytes into a {@link RawPacket}. * * This is a total, synchronous, pure function: given bytes, it either returns a structurally valid `RawPacket` or throws {@link ProtectProtocolError}. It never * returns `null` and never logs - classification of *valid-but-unmodeled* packets is the classifier's concern, and observability is the caller's. zlib inflation is * performed synchronously: realtime payloads are small (device-health deltas), so the cost is microseconds, and a pure synchronous codec is far simpler to compose * and test than an async one. * * @param buf - The raw packet bytes. Accepts any `Uint8Array` (a `Buffer` included) and reads it without copying. * * @returns The decoded {@link RawPacket}. * * @throws {@link ProtectProtocolError} if the bytes are malformed: too short to hold a header, internally inconsistent frame sizes, frames in the wrong order, an * action frame that is not a valid JSON header, an unrecognized payload-format byte, unparseable JSON, or a corrupt deflate stream. * * @category Codec */ export declare function decodePacket(buf: Uint8Array): RawPacket; /** * Encode a {@link RawPacket} back into its on-the-wire byte representation. The inverse of {@link decodePacket}; round-tripping `decode(encode(packet))` reproduces * the packet. Frames are written uncompressed (the deflate flag is the controller's optimization, not something a consumer needs to reproduce, and the decoder reads * both forms). The data frame's format byte is chosen from the payload's runtime type: a `Buffer`/`Uint8Array` encodes as a raw buffer, a `string` as UTF-8, and * anything else as JSON. * * @param packet - The packet to encode. * * @returns The encoded bytes as a `Buffer`. * * @category Codec */ export declare function encodePacket(packet: RawPacket): Buffer; //# sourceMappingURL=packet.d.ts.map