UNPKG

@seriousme/opifex

Version:

MQTT client & server for Deno & NodeJS

95 lines 2.81 kB
import type { TBitMask, Topic, TopicFilter } from "./types.ts"; /** * Checks if a specific bit flag is set in a byte using a bitmask * @param byte - The byte to check * @param mask - The bitmask to apply * @returns True if the flag is set, false otherwise */ export declare function booleanFlag(byte: number, mask: TBitMask): boolean; /** * Checks if a buffer is empty, throws error if not empty * @param buf - The buffer to check * @throws {DecoderError} If buffer is not empty */ export declare function isEmptyBuf(buf: Uint8Array): void; /** * Checks if flags are empty (zero), throws error if not * @param flags - The flags value to check * @throws {DecoderError} If flags are not zero */ export declare function hasEmptyFlags(flags: number): void; /** * Custom error class for decoder errors */ export declare class DecoderError extends Error { constructor(message: string); } /** * Decoder class for parsing MQTT packets */ export declare class Decoder { private buf; private pos; private len; /** * Creates a new Decoder instance * @param buf - The buffer to decode * @param pos - Starting position in the buffer (default: 0) */ constructor(buf: Uint8Array, pos?: number); /** * Checks if the current position is valid * @param pos - Position to check * @throws {DecoderError} If position exceeds buffer length */ checkpos(pos: number): void; /** * Gets a single byte from the buffer * @returns The byte value */ getByte(): number; /** * Gets a 16-bit integer from the buffer * @returns The 16-bit integer value */ getInt16(): number; /** * Gets a byte array from the buffer * @returns A subarray of the buffer */ getByteArray(): Uint8Array; /** * Gets a UTF-8 string from the buffer * @returns The decoded UTF-8 string */ getUtf8String(): string; /** * Gets a topic from the buffer * @returns The decoded topic * @throws {DecoderError} If topic is invalid */ getTopic(): Topic; /** * Gets a topic filter from the buffer * @returns The decoded topic filter * @throws {DecoderError} If topic filter is invalid */ getTopicFilter(): TopicFilter; /** * Gets the remaining bytes from the current position to the end * @returns The remaining bytes as a subarray */ getRemainder(): Uint8Array<ArrayBufferLike>; /** * Checks if decoder has reached the end of the buffer * @returns True if at end, false otherwise */ atEnd(): boolean; /** * Checks if decoding is complete * @returns True if complete * @throws {DecoderError} If packet is too long */ done(): boolean; } //# sourceMappingURL=decoder.d.ts.map