Files
node-screenlogic/messages/SLGetGatewayDataMessage.js
Parnic ed99d411b2 Minor optimization to set buffer size appropriately
This avoids unnecessary allocations/reallocations while decoding a message by pre-sizing the buffer to the amount we know it will require. I feel like there's probably a better way to handle this, but this works for now.
2020-02-10 21:36:13 -06:00

41 lines
866 B
JavaScript

'use strict';
const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 18003;
exports.SLGetGatewayDataMessage = class SLGetGatewayDataMessage extends SLMessage {
constructor(buf) {
var size;
if (buf) {
size = buf.readInt32LE(4) + 8;
}
super(0, MSG_ID, size);
if (typeof buf === 'string') {
this.writeSLString(buf);
this.writeSLString(buf);
} else if (buf) {
this._wroteSize = true;
this.writeBuffer(buf, 0);
this.decode();
}
}
decode() {
super.decode();
this.gatewayFound = this.readUInt8() !== 0;
this.licenseOK = this.readUInt8() !== 0;
this.ipAddr = this.readSLString();
this.port = this.readUInt16LE();
this.portOpen = this.readUInt8() !== 0;
this.relayOn = this.readUInt8() !== 0;
}
static getResponseId() {
return MSG_ID + 1;
}
};