/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
import { type InboundSequencedContainerRuntimeMessage } from "../messageTypes.js";
import { OpDecompressor } from "./opDecompressor.js";
import { OpGroupingManager } from "./opGroupingManager.js";
import { OpSplitter } from "./opSplitter.js";
/** Messages being received as a batch, with details needed to process the batch */
export interface InboundBatch {
    /** Messages in this batch */
    readonly messages: InboundSequencedContainerRuntimeMessage[];
    /** Batch ID, if present */
    readonly batchId: string | undefined;
    /** clientId that sent this batch. Used to compute Batch ID if needed */
    readonly clientId: string;
    /**
     * Client Sequence Number of the first message in the batch.
     * Used to compute Batch ID if needed
     *
     * @remarks For chunked batches, this is the CSN of the "representative" chunk (the final chunk).
     * For grouped batches, clientSequenceNumber on messages is overwritten, so we track this original value here.
     */
    readonly batchStartCsn: number;
    /** For an empty batch (with no messages), we need to remember the empty grouped batch's sequence number */
    readonly emptyBatchSequenceNumber?: number;
}
/**
 * Stateful class for processing incoming remote messages as the virtualization measures are unwrapped,
 * potentially across numerous inbound ops.
 *
 * @internal
 */
export declare class RemoteMessageProcessor {
    private readonly opSplitter;
    private readonly opDecompressor;
    private readonly opGroupingManager;
    /**
     * The current batch being received, with details needed to process it.
     *
     * @remarks If undefined, we are expecting the next message to start a new batch.
     */
    private batchInProgress;
    constructor(opSplitter: OpSplitter, opDecompressor: OpDecompressor, opGroupingManager: OpGroupingManager);
    get partialMessages(): ReadonlyMap<string, string[]>;
    clearPartialMessagesFor(clientId: string): void;
    /**
     * Ungroups and Unchunks the runtime ops of a batch received over the wire
     * @param remoteMessageCopy - A shallow copy of a message from another client, possibly virtualized
     * (grouped, compressed, and/or chunked).
     * Being a shallow copy, it's considered mutable, meaning no other Container or other parallel procedure
     * depends on this object instance.
     * Note remoteMessageCopy.contents (and other object props) MUST not be modified,
     * but may be overwritten (as is the case with contents).
     *
     * Incoming messages will always have compression, chunking, and grouped batching happen in a defined order and that order cannot be changed.
     * When processing these messages, the order is:
     * 1. If chunked, process the chunk and only continue if this is a final chunk
     * 2. If compressed, decompress the message and store for further unrolling of the decompressed content
     * 3. If grouped, ungroup the message
     * For more details, see https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/src/opLifecycle/README.md#inbound
     *
     * @returns all the unchunked, decompressed, ungrouped, unpacked InboundSequencedContainerRuntimeMessage from a single batch
     * or undefined if the batch is not yet complete.
     */
    process(remoteMessageCopy: ISequencedDocumentMessage, logLegacyCase: (codePath: string) => void): InboundBatch | undefined;
    /**
     * Add the given message to the current batch, and indicate whether the batch is now complete.
     *
     * @returns batchEnded: true if the batch is now complete, batchEnded: false if more messages are expected
     */
    private addMessageToBatch;
}
/**
 * Takes an incoming message and if the contents is a string, JSON.parse's it in place
 * @param mutableMessage - op message received
 * @param hasModernRuntimeMessageEnvelope - false if the message does not contain the modern op envelop where message.type is MessageType.Operation
 * @param logLegacyCase - callback to log when legacy op is encountered
 */
export declare function ensureContentsDeserialized(mutableMessage: ISequencedDocumentMessage, hasModernRuntimeMessageEnvelope: boolean, logLegacyCase: (codePath: string) => void): void;
/**
 * Unpacks runtime messages.
 *
 * @remarks This API makes no promises regarding backward-compatibility. This is internal API.
 * @param message - message (as it observed in storage / service)
 * @returns whether the given message was unpacked
 *
 * @internal
 */
export declare function unpackRuntimeMessage(message: ISequencedDocumentMessage, logLegacyCase?: (codePath: string) => void): boolean;
//# sourceMappingURL=remoteMessageProcessor.d.ts.map