"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeSpreadAppliedVoteHashReq = serializeSpreadAppliedVoteHashReq;
exports.deserializeSpreadAppliedVoteHashReq = deserializeSpreadAppliedVoteHashReq;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cSpreadAppliedVoteHashReqVersion = 1;
function serializeSpreadAppliedVoteHashReq(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cSpreadAppliedVoteHash);
    }
    stream.writeUInt8(cSpreadAppliedVoteHashReqVersion);
    stream.writeString(obj.txid);
    stream.writeString(obj.voteHash);
    stream.writeInt16(obj.voteTime);
    if (obj.sign) {
        stream.writeUInt8(1);
        stream.writeString(obj.sign.owner);
        stream.writeString(obj.sign.sig);
    }
    else {
        stream.writeUInt8(0);
    }
}
function deserializeSpreadAppliedVoteHashReq(stream) {
    const version = stream.readUInt8();
    if (version > cSpreadAppliedVoteHashReqVersion) {
        throw new Error('Unsupported version');
    }
    const txid = stream.readString();
    const voteHash = stream.readString();
    const voteTime = stream.readUInt16();
    let sign;
    if (stream.readUInt8() === 1) {
        sign = {
            owner: stream.readString(),
            sig: stream.readString(),
        };
        return {
            txid,
            voteHash,
            voteTime,
            sign,
        };
    }
    return {
        txid,
        voteHash,
        voteTime,
    };
}
//# sourceMappingURL=SpreadAppliedVoteHashReq.js.map