var protocol = require('pomelo-protocol');
var Package = protocol.Package;
var logger = require('pomelo-logger').getLogger('pomelo', __filename);

var handlers = {};

var ST_INITED = 0;
var ST_WAIT_ACK = 1;
var ST_WORKING = 2;
var ST_CLOSED = 3;

var handleHandshake = function(socket, pkg) {
	if(socket.state !== ST_INITED) {
    return;
  }
	socket.emit('handshake', JSON.parse(protocol.strdecode(pkg.body)));
};

var handleHandshakeAck = function(socket, pkg) {
	if(socket.state !== ST_WAIT_ACK) {
    return;
  }
  socket.state = ST_WORKING;
	socket.emit('heartbeat');
};

var handleHeartbeat = function(socket, pkg) {
	if(socket.state !== ST_WORKING) {
    return;
  }
	socket.emit('heartbeat');
};

var handleData = function(socket, pkg) {
	if(socket.state !== ST_WORKING) {
    return;
  }
	socket.emit('message', pkg);
};

handlers[Package.TYPE_HANDSHAKE] = handleHandshake;
handlers[Package.TYPE_HANDSHAKE_ACK] = handleHandshakeAck;
handlers[Package.TYPE_HEARTBEAT] = handleHeartbeat;
handlers[Package.TYPE_DATA] = handleData;

var handle = function(socket, pkg) {
  var handler = handlers[pkg.type];
  if(!!handler) {
    handler(socket, pkg);
  }	else {
    logger.error('could not find handle invalid data package.');
    socket.disconnect();
  }
};

module.exports = handle;
@@ -278,33 +278,34 @@
 (socket, pkg) %7B%0A
-%09
+  
 if(socket.state 
@@ -329,33 +329,34 @@
     return;%0A  %7D%0A
-%09
+  
 socket.emit('han
@@ -452,33 +452,34 @@
 (socket, pkg) %7B%0A
-%09
+  
 if(socket.state 
@@ -542,17 +542,18 @@
 ORKING;%0A
-%09
+  
 socket.e
@@ -612,33 +612,34 @@
 (socket, pkg) %7B%0A
-%09
+  
 if(socket.state 
@@ -664,33 +664,34 @@
     return;%0A  %7D%0A
-%09
+  
 socket.emit('hea
@@ -745,17 +745,18 @@
  pkg) %7B%0A
-%09
+  
 if(socke
@@ -797,17 +797,18 @@
 rn;%0A  %7D%0A
-%09
+  
 socket.e
@@ -1162,9 +1162,9 @@
 %0A  %7D
-%09
+ 
 else
@@ -1288,8 +1288,9 @@
  handle;
+%0A

code style, replace ^I with 2 spaces