parser: fix header parsing.
This commit is contained in:
parent
2881294bf4
commit
3f5c5cf603
@ -127,7 +127,6 @@ Parser.prototype.parse = function parse(data) {
|
|||||||
|
|
||||||
if (!this.header) {
|
if (!this.header) {
|
||||||
this.header = this.parseHeader(data);
|
this.header = this.parseHeader(data);
|
||||||
this.waiting = this.header.size;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,15 +144,16 @@ Parser.prototype.parse = function parse(data) {
|
|||||||
try {
|
try {
|
||||||
payload = this.parsePayload(this.header.cmd, data);
|
payload = this.parsePayload(this.header.cmd, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.emit('error', e);
|
|
||||||
this.waiting = 24;
|
this.waiting = 24;
|
||||||
this.header = null;
|
this.header = null;
|
||||||
|
this.emit('error', e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('packet', payload);
|
|
||||||
this.waiting = 24;
|
this.waiting = 24;
|
||||||
this.header = null;
|
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));
|
return this.error('Packet length too large: %dmb.', utils.mb(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.waiting = size;
|
||||||
|
|
||||||
checksum = data.readUInt32LE(20, true);
|
checksum = data.readUInt32LE(20, true);
|
||||||
|
|
||||||
return new Header(cmd, size, checksum);
|
return new Header(cmd, size, checksum);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user