"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeSpreadTxToGroupSyncingReq = exports.serializeSpreadTxToGroupSyncingReq = void 0;
const lib_types_1 = require("@shardeum-foundation/lib-types");
const Context_1 = require("../p2p/Context");
const shardus_types_1 = require("../shardus/shardus-types");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cSpreadTxToGroupSyncingReqVersion = 1;
function serializeSpreadTxToGroupSyncingReq(stream, inp, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cSpreadTxToGroupSyncingReq);
    }
    stream.writeUInt8(cSpreadTxToGroupSyncingReqVersion);
    stream.writeBigUInt64(BigInt(inp.timestamp));
    stream.writeString(inp.txId);
    stream.writeString(lib_types_1.Utils.safeStringify(inp.keys));
    stream.writeString(lib_types_1.Utils.safeStringify(inp.data));
    stream.writeBuffer(Context_1.stateManager.app.binarySerializeObject(shardus_types_1.AppObjEnum.AppData, inp.appData));
    stream.writeString(lib_types_1.Utils.safeStringify(inp.shardusMemoryPatterns));
}
exports.serializeSpreadTxToGroupSyncingReq = serializeSpreadTxToGroupSyncingReq;
function deserializeSpreadTxToGroupSyncingReq(stream) {
    const version = stream.readUInt8();
    if (version > cSpreadTxToGroupSyncingReqVersion) {
        throw new Error('SpreadTxToGroupSyncingReq Unsupported version');
    }
    return {
        timestamp: Number(stream.readBigUInt64()),
        txId: stream.readString(),
        keys: lib_types_1.Utils.safeJsonParse(stream.readString()),
        data: lib_types_1.Utils.safeJsonParse(stream.readString()),
        appData: Context_1.stateManager.app.binaryDeserializeObject(shardus_types_1.AppObjEnum.AppData, stream.readBuffer()),
        shardusMemoryPatterns: lib_types_1.Utils.safeJsonParse(stream.readString()),
    };
}
exports.deserializeSpreadTxToGroupSyncingReq = deserializeSpreadTxToGroupSyncingReq;
//# sourceMappingURL=SpreadTxToGroupSyncingReq.js.map