UNPKG

@node-dlc/messaging

Version:
61 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DlcInfoV0 = exports.DlcInfo = void 0; const bufio_1 = require("@node-dlc/bufio"); const MessageType_1 = require("../MessageType"); /** * DlcInfo message contains list of buffers */ class DlcInfo { constructor() { /** * The type for dlc_info message */ this.type = DlcInfo.type; } static deserialize(buf) { const reader = new bufio_1.BufferReader(buf); const type = Number(reader.readUInt16BE()); switch (type) { case MessageType_1.MessageType.DlcInfoV0: return DlcInfo.deserializeV0(buf); default: throw new Error(`DLC Info message type must be DlcInfoV0`); } } /** * Deserializes an dlc_info message * @param buf */ static deserializeV0(buf) { const instance = new DlcInfo(); const reader = new bufio_1.BufferReader(buf); reader.readUInt16BE(); // read type instance.numDlcOffers = reader.readUInt32BE(); instance.numDlcAccepts = reader.readUInt32BE(); instance.numDlcSigns = reader.readUInt32BE(); instance.numDlcCancels = reader.readUInt32BE(); instance.numDlcCloses = reader.readUInt32BE(); instance.numDlcTransactions = reader.readUInt32BE(); return instance; } /** * Serializes the dlc_info message into a Buffer */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeUInt16BE(this.type); writer.writeUInt32BE(this.numDlcOffers); writer.writeUInt32BE(this.numDlcAccepts); writer.writeUInt32BE(this.numDlcSigns); writer.writeUInt32BE(this.numDlcCancels); writer.writeUInt32BE(this.numDlcCloses); writer.writeUInt32BE(this.numDlcTransactions); return writer.toBuffer(); } } exports.DlcInfo = DlcInfo; DlcInfo.type = MessageType_1.MessageType.DlcInfo; // Legacy support - keeping old class name as alias exports.DlcInfoV0 = DlcInfo; //# sourceMappingURL=DlcInfo.js.map