@node-dlc/messaging
Version:
DLC Messaging Protocol
63 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DlcInfoV0 = exports.DlcInfo = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
class DlcInfo {
static deserialize(buf) {
const reader = new bufio_1.BufferReader(buf);
const type = Number(reader.readUInt16BE());
switch (type) {
case MessageType_1.MessageType.DlcInfoV0:
return DlcInfoV0.deserialize(buf);
default:
throw new Error(`DLC IDs message type must be DlcInfoV0`);
}
}
}
exports.DlcInfo = DlcInfo;
/**
* DlcInfo message contains list of buffers
*/
class DlcInfoV0 extends DlcInfo {
constructor() {
super(...arguments);
/**
* The type for dlc_info_v0 message
*/
this.type = DlcInfoV0.type;
}
/**
* Deserializes an dlc_ids_v0 message
* @param buf
*/
static deserialize(buf) {
const instance = new DlcInfoV0();
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_v0 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.DlcInfoV0 = DlcInfoV0;
DlcInfoV0.type = MessageType_1.MessageType.DlcInfoV0;
//# sourceMappingURL=DlcInfo.js.map