UNPKG

zigbee-herdsman

Version:

An open source ZigBee gateway solution with node.js.

43 lines 1.18 kB
"use strict"; /* istanbul ignore file */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ZBOSSWriter = void 0; const stream_1 = require("stream"); class ZBOSSWriter extends stream_1.Readable { bytesToWrite; constructor(opts) { super(opts); this.bytesToWrite = []; } writeBytes() { const buffer = Buffer.from(this.bytesToWrite); this.bytesToWrite = []; // expensive and very verbose, enable locally only if necessary // logger.debug(`>>>> [FRAME raw=${buffer.toString('hex')}]`, NS); // this.push(buffer); this.emit('data', buffer); } writeByte(byte) { this.bytesToWrite.push(byte); } writeAvailable() { if (this.readableLength < this.readableHighWaterMark) { return true; } else { this.writeFlush(); return false; } } /** * If there is anything to send, send to the port. */ writeFlush() { if (this.bytesToWrite.length) { this.writeBytes(); } } _read() { } } exports.ZBOSSWriter = ZBOSSWriter; //# sourceMappingURL=writer.js.map