/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { assert } from "@fluidframework/core-utils";
import { makeVersionedValidatedCodec } from "../../codec";
import { Format } from "./format";
export function makeForestSummarizerCodec(options, fieldBatchCodec) {
    const inner = fieldBatchCodec;
    return makeVersionedValidatedCodec(options, new Set([1]), Format, {
        encode: (data) => {
            const keys = [];
            const fields = [];
            for (const [key, value] of data) {
                keys.push(key);
                fields.push(value);
            }
            return { keys, fields: inner.encode(fields), version: 1 };
        },
        decode: (data) => {
            const out = new Map();
            const fields = inner.decode(data.fields);
            assert(data.keys.length === fields.length, 0x891 /* mismatched lengths */);
            for (let index = 0; index < fields.length; index++) {
                out.set(data.keys[index], fields[index]);
            }
            return out;
        },
    });
}
//# sourceMappingURL=codec.js.map