/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { FieldKey, FieldStoredSchema, ITreeCursorSynchronous, TreeSchemaIdentifier, Value } from "../../../core";
import { BufferFormat as BufferFormatGeneric, Shape as ShapeGeneric } from "./chunkEncodingGeneric";
import { Counter, DeduplicationTable } from "./chunkCodecUtilities";
import { EncodedChunk, EncodedChunkShape, EncodedValueShape } from "./format";
/**
 * Encode data from `cursor` in into an `EncodedChunk`.
 *
 * Optimized for encoded size and encoding performance.
 *
 * Most of the compression strategy comes from the policy provided via `cache`.
 */
export declare function compressedEncode(cursor: ITreeCursorSynchronous, cache: EncoderCache): EncodedChunk;
export declare type BufferFormat = BufferFormatGeneric<EncodedChunkShape>;
export declare type Shape = ShapeGeneric<EncodedChunkShape>;
/**
 * Like {@link FieldEncoder}, except data will be prefixed with the key.
 */
export interface KeyedFieldEncoder {
    readonly key: FieldKey;
    readonly shape: FieldEncoder;
}
/**
 * An encoder with an associated shape.
 */
export interface Encoder {
    /**
     * The shape which describes how the encoded data is laid out.
     * Used by decoders to interpret the output of `encodeNode`.
     */
    readonly shape: Shape;
}
/**
 * An encoder for a specific shape of node.
 *
 * Can only be used with compatible nodes.
 */
export interface NodeEncoder extends Encoder {
    /**
     * @param cursor - in Nodes mode. Does not move cursor.
     */
    encodeNode(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat): void;
}
/**
 * Like {@link NodeEncoder}, except encodes a run of nodes.
 */
export interface NodesEncoder extends Encoder {
    /**
     * @param cursor - in Nodes mode. Moves cursor however many nodes it encodes.
     */
    encodeNodes(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat): void;
}
/**
 * Like {@link NodeEncoder}, except encodes a field.
 */
export interface FieldEncoder extends Encoder {
    /**
     * @param cursor - in Fields mode. Encodes entire field.
     */
    encodeField(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat): void;
}
/**
 * Makes a {@link FieldEncoder} which runs `encoder` on every node in the field.
 * This does not encode the number nodes: the user of this may need to encode that elsewhere.
 */
export declare function asFieldEncoder(encoder: NodeEncoder): FieldEncoder;
/**
 * Adapt a {@link NodeEncoder} to a {@link NodesEncoder} which invokes `encoder` once.
 */
export declare function asNodesEncoder(encoder: NodeEncoder): NodesEncoder;
/**
 * Encodes a chunk with {@link EncodedAnyShape} by prefixing the data with its shape.
 */
export declare class AnyShape extends ShapeGeneric<EncodedChunkShape> {
    private constructor();
    static readonly instance: AnyShape;
    encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
    count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
    static encodeField(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: FieldEncoder): void;
    static encodeNode(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: NodeEncoder): void;
    static encodeNodes(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: NodesEncoder): void;
}
/**
 * Encodes a single node polymorphically.
 */
export declare const anyNodeEncoder: NodeEncoder;
/**
 * Encodes a field polymorphically.
 */
export declare const anyFieldEncoder: FieldEncoder;
/**
 * Encodes a chunk using {@link EncodedInlineArray}.
 */
export declare class InlineArrayShape extends ShapeGeneric<EncodedChunkShape> implements NodesEncoder, FieldEncoder {
    readonly length: number;
    readonly inner: NodesEncoder;
    static readonly empty: InlineArrayShape;
    /**
     * @param length - number of invocations of `inner`.
     */
    constructor(length: number, inner: NodesEncoder);
    encodeNodes(cursor: ITreeCursorSynchronous, shapes: EncoderCache, outputBuffer: BufferFormat): void;
    encodeField(cursor: ITreeCursorSynchronous, shapes: EncoderCache, outputBuffer: BufferFormat): void;
    encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
    count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
    get shape(): this;
}
/**
 * Encodes a field as a nested array with the {@link EncodedNestedArray} shape.
 */
export declare class NestedArrayShape extends ShapeGeneric<EncodedChunkShape> implements FieldEncoder {
    readonly inner: NodeEncoder;
    readonly shape: Shape;
    constructor(inner: NodeEncoder);
    encodeField(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat): void;
    encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
    count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
}
/**
 * Encode `value` with `shape` into `outputBuffer`.
 *
 * Requires that `value` is compatible with `shape`.
 */
export declare function encodeValue(value: Value, shape: EncodedValueShape, outputBuffer: BufferFormat): void;
export declare class EncoderCache implements TreeShaper, FieldShaper {
    private readonly treeEncoder;
    private readonly fieldEncoder;
    private readonly shapesFromSchema;
    private readonly nestedArrays;
    constructor(treeEncoder: TreeShapePolicy, fieldEncoder: FieldShapePolicy);
    shapeFromTree(schemaName: TreeSchemaIdentifier): NodeEncoder;
    nestedArray(inner: NodeEncoder): NestedArrayShape;
    shapeFromField(field: FieldStoredSchema): FieldEncoder;
}
export interface TreeShaper {
    shapeFromTree(schemaName: TreeSchemaIdentifier): NodeEncoder;
}
export interface FieldShaper {
    shapeFromField(field: FieldStoredSchema): FieldEncoder;
}
export declare type FieldShapePolicy = (treeShaper: TreeShaper, field: FieldStoredSchema) => FieldEncoder;
export declare type TreeShapePolicy = (fieldShaper: FieldShaper, schemaName: TreeSchemaIdentifier) => NodeEncoder;
//# sourceMappingURL=compressedEncode.d.ts.map