"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeGossipReq = exports.serializeGossipReq = void 0;
const lib_types_1 = require("@shardeum-foundation/lib-types");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cGossipReqVersion = 1;
function serializeGossipReq(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGossipReq);
    }
    stream.writeUInt8(cGossipReqVersion);
    stream.writeString(obj.type);
    stream.writeString(lib_types_1.Utils.safeStringify(obj.data));
}
exports.serializeGossipReq = serializeGossipReq;
function deserializeGossipReq(stream) {
    const version = stream.readUInt8();
    if (version > cGossipReqVersion) {
        throw new Error('GossipReq version mismatch');
    }
    const type = stream.readString();
    const data = lib_types_1.Utils.safeJsonParse(stream.readString());
    return { type, data };
}
exports.deserializeGossipReq = deserializeGossipReq;
//# sourceMappingURL=GossipReq.js.map