"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeCompareCertReq = exports.serializeCompareCertReq = exports.cCompareCertReqVersion = void 0;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const lib_types_1 = require("@shardeum-foundation/lib-types");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
exports.cCompareCertReqVersion = 1;
const serializeCompareCertReq = (stream, inp, root = false) => {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cCompareCertReq);
    }
    stream.writeUInt8(exports.cCompareCertReqVersion);
    stream.writeString(lib_types_1.Utils.safeStringify(inp));
};
exports.serializeCompareCertReq = serializeCompareCertReq;
const deserializeCompareCertReq = (stream) => {
    const version = stream.readUInt8();
    if (version > exports.cCompareCertReqVersion) {
        throw new Error(`Unsupported CompareCertReqSerializable version ${version}`);
    }
    const obj = lib_types_1.Utils.safeJsonParse(stream.readString());
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.CompareCertReq, obj);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return obj;
};
exports.deserializeCompareCertReq = deserializeCompareCertReq;
//# sourceMappingURL=CompareCertReq.js.map