import * as model from "./model"; import * as mqtt5_packet from '../../common/mqtt5_packet'; import * as mqtt_shared from "../../common/mqtt_shared"; /** * The encoder works similarly to the native MQTT5 client in aws-c-mqtt: * * Encoding is a two-step process. * * The first step takes the finalized packet and pushes one or more "steps" * onto a queue. Each step represents the encoding of a single primitive integer or range of bytes. * * The second step involves iterating the encoding steps and performing them on a mutable buffer that represents * a range of bytes to write to the socket. * * If the buffer fills up, encoding is halted (byte ranges are clipped in place) and the buffer is considered * ready to send to the socket. The client only has one buffer in-flight at once (the write completion callback * must be invoked in order to continue encoding). * * There isn't a pressing need to do it this way other than familiarity (the minimal allocation and hot-buffer * properties probably aren't particular impactful in JS). */ export declare enum EncodingStepType { U8 = 0, U16 = 1, U32 = 2, VLI = 3, BYTES = 4 } export interface EncodingStep { type: EncodingStepType; value: number | DataView; } export declare function encodeLengthPrefixedArrayBuffer(steps: Array, source: ArrayBuffer | undefined): void; export declare function encodeOptionalLengthPrefixedArrayBuffer(steps: Array, source: ArrayBuffer | undefined): void; export declare function encodeRequiredLengthPrefixedArrayBuffer(steps: Array, source: ArrayBuffer): void; export declare function computeUserPropertiesLength(user_properties: Array | undefined): number; export declare function encodeUserProperties(steps: Array, user_properties: Array | undefined): void; export declare function computePacketEncodingLength(packet: model.IPacketBinary, mode: mqtt_shared.ProtocolMode): number; export type EncodingFunction = (steps: Array, packet: model.IPacketBinary) => void; export type EncodingFunctionSet = Map; export declare function buildClientEncodingFunctionSet(mode: mqtt_shared.ProtocolMode): EncodingFunctionSet; export declare enum ServiceResultType { Complete = 0, InProgress = 1 } export interface ServiceResult { type: ServiceResultType; encodedView?: DataView; nextView: DataView; } /** * Encoder implementation. All failures are surfaced as exceptions and considered protocol-fatal. * * The implementation assumes full, stringent validation has been performed prior to encoding (ie all packets are * protocol-compliant). */ export declare class Encoder { private encoders; private packet; private steps; private currentStep; constructor(encoders: EncodingFunctionSet); reset(): void; initForPacket(packet: model.IPacketBinary): void; service(dest: DataView): ServiceResult; }