UNPKG

@node-dlc/messaging

Version:
60 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DlcIdsV0 = exports.DlcIds = void 0; const bufio_1 = require("@node-dlc/bufio"); const MessageType_1 = require("../MessageType"); class DlcIds { static deserialize(buf) { const reader = new bufio_1.BufferReader(buf); const type = Number(reader.readUInt16BE()); switch (type) { case MessageType_1.MessageType.DlcIdsV0: return DlcIdsV0.deserialize(buf); default: throw new Error(`DLC IDs message type must be DlcIdsV0`); } } } exports.DlcIds = DlcIds; /** * DlcIds message contains list of buffers */ class DlcIdsV0 extends DlcIds { constructor() { super(...arguments); /** * The type for dlc_ids_v0 message */ this.type = DlcIdsV0.type; this.ids = []; } /** * Deserializes an dlc_ids_v0 message * @param buf */ static deserialize(buf) { const instance = new DlcIdsV0(); const reader = new bufio_1.BufferReader(buf); reader.readUInt16BE(); // read type const idsLen = reader.readBigSize(); // ids length for (let i = 0; i < idsLen; i++) { instance.ids.push(reader.readBytes(32)); } return instance; } /** * Serializes the dlc_ids_v0 message into a Buffer */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeUInt16BE(this.type); writer.writeBigSize(this.ids.length); for (const id of this.ids) { writer.writeBytes(id); } return writer.toBuffer(); } } exports.DlcIdsV0 = DlcIdsV0; DlcIdsV0.type = MessageType_1.MessageType.DlcIdsV0; //# sourceMappingURL=DlcIds.js.map