"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeConfirmOrChallengeMessage = exports.serializeConfirmOrChallengeMessage = exports.cConfirmOrChallengeMessageVersion = void 0;
const AppliedVote_1 = require("./AppliedVote");
const Sign_1 = require("./Sign");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cConfirmOrChallengeMessageVersion = 1;
function serializeConfirmOrChallengeMessage(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cConfirmOrChallengeMessage);
    }
    stream.writeUInt8(exports.cConfirmOrChallengeMessageVersion);
    stream.writeString(obj.message);
    stream.writeString(obj.nodeId);
    (0, AppliedVote_1.serializeAppliedVote)(stream, obj.appliedVote);
    if (obj.sign) {
        stream.writeUInt8(1);
        (0, Sign_1.serializeSign)(stream, obj.sign);
    }
    else {
        stream.writeUInt8(0);
    }
}
exports.serializeConfirmOrChallengeMessage = serializeConfirmOrChallengeMessage;
function deserializeConfirmOrChallengeMessage(stream) {
    const version = stream.readUInt8();
    if (version > exports.cConfirmOrChallengeMessageVersion) {
        throw new Error(`ConfirmOrChallengeMessageDeserializer expected version ${exports.cConfirmOrChallengeMessageVersion}, got ${version}`);
    }
    const message = stream.readString();
    const nodeId = stream.readString();
    const appliedVote = (0, AppliedVote_1.deserializeAppliedVote)(stream);
    const sign = stream.readUInt8() === 1 ? (0, Sign_1.deserializeSign)(stream) : undefined;
    return {
        message,
        nodeId,
        appliedVote,
        sign,
    };
}
exports.deserializeConfirmOrChallengeMessage = deserializeConfirmOrChallengeMessage;
//# sourceMappingURL=ConfirmOrChallengeMessage.js.map