import { fromBase64, toBase64 } from "@peerbit/crypto";
export const resolveValue = (value) => {
    if (value.type === "simple") {
        return value.value;
    }
    return value.encoding === "clone" ? value.value : fromBase64(value.base64);
};
export const encodeValue = (value, protocol = "legacy") => {
    if (value instanceof Uint8Array) {
        return protocol === "clone"
            ? { type: "uint8array", encoding: "clone", value }
            : { type: "uint8array", encoding: "base64", base64: toBase64(value) };
    }
    return { type: "simple", value };
};
export const encodeValues = (values, protocol = "legacy") => {
    if (!values || values.length === 0) {
        return {
            values,
            metrics: {
                encodeMs: 0,
                valueCount: 0,
                blobValueCount: 0,
                blobBytes: 0,
            },
        };
    }
    let blobBytes = 0;
    let blobValueCount = 0;
    const startedAt = performance.now();
    const encodedValues = values.map((value) => {
        if (value instanceof Uint8Array) {
            blobValueCount++;
            blobBytes += value.byteLength;
        }
        return encodeValue(value, protocol);
    });
    return {
        values: encodedValues,
        metrics: {
            encodeMs: performance.now() - startedAt,
            valueCount: values.length,
            blobValueCount,
            blobBytes,
        },
    };
};
//# sourceMappingURL=sqlite3-messages.worker.js.map