Skip to content

Commit

Permalink
Parser variable order consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
reid committed Jun 16, 2012
1 parent db6f802 commit 01805a8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/blizzard/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,18 @@ BlizzardSession.prototype.setupBinaryParser = function (socket) {
var self = this;

function parser(onPacket) {
var emit,
buffer = null,
var buffer = null,
type = null,
offset = 0,
payloadLength = 0,
id,
type,
state = 0;
state = 0,
id = 0;
return function emitter(chunk) {
var i = 0,
byte,
emit = false,
chunkLength = chunk.length,
chunkPayloadLength,
chunkLength = chunk.length;
byte;
for (; i < chunkLength; i += 1) {
byte = chunk[i];
switch (state) {
Expand Down Expand Up @@ -477,16 +477,15 @@ BlizzardSession.prototype.setupBinaryParser = function (socket) {
break;
case 9:
payloadLength |= byte;
state = 10;
if (payloadLength > 0) {
state = 10;
buffer = new Buffer(payloadLength);
} else {
emit = true;
}
break;
// data
case 10:
emit = false;
chunkPayloadLength = chunkLength - i;
if (chunkPayloadLength + offset >= payloadLength) {
emit = true;
Expand All @@ -499,11 +498,12 @@ BlizzardSession.prototype.setupBinaryParser = function (socket) {
}
if (emit) {
onPacket(type, id, buffer);
id = 0;
state = 0;
payloadLength = 0;
offset = 0;
buffer = null;
type = null;
offset = 0;
payloadLength = 0;
state = 0;
id = 0;
emit = false;
}
}
Expand Down

0 comments on commit 01805a8

Please sign in to comment.