@Override
	protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) 
		throws Exception {
		final int origonPos = in.position();
        final int packetLength = in.remaining();
        
        if(packetLength<PROTOCOL_HEADER_LENGTH){
        	in.position(origonPos);
        	return false;
        }
        
        int flag  = in.getInt();
        int chid  = in.getInt();
        int pcode = in.getInt();
        int len   = in.getInt();
        
        if (flag != TairConstant.TAIR_PACKET_FLAG)
        	throw new IOException("flag error, except: " + TairConstant.TAIR_PACKET_FLAG + ", but get " + flag);
        
        if (in.remaining() < len) {
        	in.position(origonPos);
        	return false;
        }
        
        if(isDebugEnabled){
	        final String remoteIP = ((InetSocketAddress) session.getRemoteAddress()).toString();
	        StringBuilder receiveTimeInfo = new StringBuilder();
	        receiveTimeInfo.append("receive response from [").append(remoteIP).append("],time is: ");
	        receiveTimeInfo.append(System.currentTimeMillis());
	        receiveTimeInfo.append(", channel id: ").append(chid);
	        LOGGER.debug(receiveTimeInfo.toString());
        }
        
        byte[] data = new byte[len];
        in.get(data);
        
        if (isDebugEnabled)
        	LOGGER.debug(TairUtil.toHex(data));
        
        BasePacket returnPacket = pstreamer.decodePacket(pcode, data);
        
        TairResponse response=new TairResponse();
        response.setRequestId(chid);
        response.setResponse(returnPacket);
        out.write(response);
        
		return true;
	}