parser: fix header parsing.

This commit is contained in:
Christopher Jeffrey 2016-09-16 19:35:04 -07:00
parent 2881294bf4
commit 3f5c5cf603
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -127,7 +127,6 @@ Parser.prototype.parse = function parse(data) {
if (!this.header) {
this.header = this.parseHeader(data);
this.waiting = this.header.size;
return;
}
@ -145,15 +144,16 @@ Parser.prototype.parse = function parse(data) {
try {
payload = this.parsePayload(this.header.cmd, data);
} catch (e) {
this.emit('error', e);
this.waiting = 24;
this.header = null;
this.emit('error', e);
return;
}
this.emit('packet', payload);
this.waiting = 24;
this.header = null;
this.emit('packet', payload);
};
/**
@ -185,6 +185,8 @@ Parser.prototype.parseHeader = function parseHeader(data) {
return this.error('Packet length too large: %dmb.', utils.mb(size));
}
this.waiting = size;
checksum = data.readUInt32LE(20, true);
return new Header(cmd, size, checksum);