@Override
	protected Object decode(ChannelHandlerContext context, Channel channel, ChannelBuffer buffer) throws Exception {
		if(context.getPipeline().get(HandshakeDecoder.class) != null) {
			context.getPipeline().remove(this);
		}
		byte serviceReq = (byte) (buffer.readByte() & 0xFF);
		ChannelBuffer msg = ChannelBuffers.dynamicBuffer();
		switch(serviceReq) {
		case JS5_PROTOCOL_REQUEST:
			int revision = buffer.readInt();
			if(revision != Configuration.REVISION) {
				msg.writeByte(6);
			} else {
				msg.writeByte(0);
				context.getPipeline().addBefore("encoder", "decoder", new JS5Decoder());
			}
			channel.write(msg);
			break;
		case LOGIN_PROTOCOL_REQUEST:
			if(1 <= buffer.readableBytes()) {
				buffer.readUnsignedByte();
				msg.writeByte(0);
				msg.writeLong(new SecureRandom().nextLong());
				context.getPipeline().addBefore("encoder", "decoder", new LoginDecoder());
				channel.write(msg);
			}
			break;
		}
		return null;
	}