/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { forEachField, forEachNode } from "../../../core";
import { version } from "./format";
/**
 * Encode data from `cursor` in the simplest way supported by `EncodedChunk`.
 *
 * No polymorphism, identifier deduplication or schema based compression.
 * Just uses two hard coded shapes and inline identifiers.
 *
 * This is intended as a simple reference implementation with minimal code and dependencies.
 */
export function uncompressedEncode(cursor) {
    const rootField = encodeSequence(cursor);
    return {
        version,
        identifiers: [],
        shapes: [{ c: anyTreeShape }, { a: anyArray }],
        data: [arrayIndex, rootField],
    };
}
const treeIndex = 0;
const arrayIndex = 1;
const anyTreeShape = {
    extraFields: arrayIndex,
    fields: [],
};
const anyArray = treeIndex;
function encodeSequence(cursor) {
    const data = [];
    forEachNode(cursor, () => {
        data.push(cursor.type);
        const value = cursor.value;
        data.push(value !== undefined);
        if (value !== undefined) {
            data.push(value);
        }
        const local = [];
        forEachField(cursor, () => {
            const key = cursor.getFieldKey();
            local.push(key, encodeSequence(cursor));
        });
        data.push(local);
    });
    return data;
}
//# sourceMappingURL=uncompressedEncode.js.map