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.
This commit is contained in:
2020-02-10 21:36:13 -06:00
parent 5a55c56ac1
commit ed99d411b2
8 changed files with 48 additions and 9 deletions

View File

@ -6,7 +6,12 @@ const MSG_ID = 12572;
exports.SLSaltCellConfigMessage = class SLSaltCellConfigMessage extends SLMessage {
constructor(buf) {
super(0, MSG_ID);
var size;
if (buf) {
size = buf.readInt32LE(4) + 8;
}
super(0, MSG_ID, size);
if (!buf) {
this.writeInt32LE(0); // controller index
} else {