UNPKG

@seriousme/opifex

Version:

MQTT client & server for Deno & NodeJS

33 lines 1.29 kB
/** * Encodes a number into a variable-length byte array using a modified base-128 encoding * @param n The number to encode * @returns Array of bytes representing the encoded number * @throws Error if the encoded length is greater than 4 bytes */ export declare function encodeLength(n: number): number[]; /** * Decodes a variable-length encoded number from a byte array * @param buf The byte array containing the encoded number * @param start The starting position in the buffer to begin decoding * @returns Object containing the decoded length and number of bytes used for encoding * @throws Error if decoding fails */ export declare function decodeLength(buf: Uint8Array, start: number): { length: number; numLengthBytes: number; }; /** * Interface for the result returned by the length decoder */ export type LengthDecoderResult = { done: boolean; length: number; numLengthBytes: number; }; /** * Creates a stateful decoder function for processing variable-length encoded numbers * @returns Function that processes one byte at a time and returns decoding status * @throws Error if the encoded length is greater than 4 bytes */ export declare function getLengthDecoder(): (encodedByte: number) => LengthDecoderResult; //# sourceMappingURL=length.d.ts.map