"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeCompareCertResp = exports.serializeCompareCertResp = exports.cCompareCertRespVersion = 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.cCompareCertRespVersion = 1;
const serializeCompareCertResp = (stream, inp, root = false) => {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cCompareCertResp);
    }
    stream.writeUInt8(exports.cCompareCertRespVersion);
    stream.writeString(lib_types_1.Utils.safeStringify(inp));
};
exports.serializeCompareCertResp = serializeCompareCertResp;
const deserializeCompareCertResp = (stream) => {
    const version = stream.readUInt8();
    if (version > exports.cCompareCertRespVersion) {
        throw new Error(`Unsupported CompareCertRespSerializable version ${version}`);
    }
    const obj = lib_types_1.Utils.safeJsonParse(stream.readString());
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.CompareCertResp, obj);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return obj;
};
exports.deserializeCompareCertResp = deserializeCompareCertResp;
//# sourceMappingURL=CompareCertResp.js.map