import { GenericChannel } from './GenericChannel';
import { TransportMessage } from '../Message';
export type ChunkedMessageStart = {
    type: 'chunk_start';
    chunkId: string;
    size: number;
};
export type ChunkedMessage = {
    type: 'chunk_data';
    chunkId: string;
    data: any;
};
export type ChunkedMessageEnd = {
    type: 'chunk_end';
    chunkId: string;
};
export type ChunkedTransportMessage = ChunkedMessageEnd | ChunkedMessageStart | ChunkedMessage;
export interface ChunkedChannelConstructorOptions {
    chunkSize: number;
    sender: (m: TransportMessage) => void;
    timeout?: number;
    maxStringAlloc?: number;
}
/**
 * Overrides the `send` and `_messageReceived` methods of the GenericChannel class
 * to offer transparent message chunking over a fragile underlying channel.
 */
export declare class ChunkedChannel extends GenericChannel {
    constructor(opts: ChunkedChannelConstructorOptions);
    /**
     * The size of the data array in each chunk.
     * Note that the total "size" of the message will be larger
     * because of the chunking metadata.
     */
    private _chunkSize;
    /**
     * Defines the maximum string length that will be allocated at once when
     * merging the buffered chunks into the original string.
     * This is only needed if the environment where this instance is running applies restriction
     * on memory for string allocation.
     * Omitting to set this will just create the string from the chunks in one go.
     */
    private _maxStringAlloc;
    /** The actual sending via the underlying channel (eg. websocket) */
    protected _sender: (m: TransportMessage | ChunkedTransportMessage) => void;
    /** Stores chunks pending flush */
    private _buffer;
    /**
     * This method override will chunk messages so that an array of no more than
     * `chunkSize` bytes (excluding internal metadata) will be sent for each call
     * to a given slot.
     */
    send(message: TransportMessage): void;
    /**
     * When a message is received on this channel, either it has been chunked because its original size
     * was greater than the chunkSize in which case it will be a `ChunkedTransportMessage`,
     * or it was small enough so that it could be sent un chunked in which
     * case it will be a plain `TransportMessage`.
     */
    protected _messageReceived(message: TransportMessage | ChunkedTransportMessage): void;
    private _receiveNewChunk;
    private _receiveChunkData;
    private _mergeChunks;
}
//# sourceMappingURL=ChunkedChannel.d.ts.map