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.
33 lines
573 B
JavaScript
Executable File
33 lines
573 B
JavaScript
Executable File
'use strict';
|
|
|
|
const SLMessage = require('./SLMessage.js').SLMessage;
|
|
|
|
const MSG_ID = 14;
|
|
|
|
exports.SLChallengeMessage = class SLChallengeMessage extends SLMessage {
|
|
constructor(buf) {
|
|
var size;
|
|
if (buf) {
|
|
size = buf.readInt32LE(4) + 8;
|
|
}
|
|
super(0, MSG_ID, size);
|
|
|
|
if (buf) {
|
|
this._wroteSize = true;
|
|
this.writeBuffer(buf, 0);
|
|
|
|
this.decode();
|
|
}
|
|
}
|
|
|
|
decode() {
|
|
super.decode();
|
|
|
|
this.challengeString = this.readSLString();
|
|
}
|
|
|
|
static getResponseId() {
|
|
return MSG_ID + 1;
|
|
}
|
|
};
|