// Path: Redis-Synyed-common/src/main/java/com/wmz7year/synyed/constant/RedisProtocolConstant.java
// public static final String REDIS_PROTOCOL_PARSER = "redis_protpcol_parser";
// 
// Path: Redis-Synyed-common/src/main/java/com/wmz7year/synyed/packet/redis/RedisPacket.java
// public abstract class RedisPacket {
// 	/**
// 	 * redis命令
// 	 */
// 	protected String command;
// 
// 	public RedisPacket(String command) {
// 		this.command = command;
// 	}
// 
// 	public String getCommand() {
// 		return command;
// 	}
// 
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// 
// 	/**
// 	 * 获取数据包原始数据的方法
// 	 * 
// 	 * @return 数据包原始数据
// 	 */
// 	public abstract byte[] getData();
// }


import static com.wmz7year.synyed.constant.RedisProtocolConstant.REDIS_PROTOCOL_PARSER;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import com.wmz7year.synyed.packet.redis.RedisPacket;
package com.wmz7year.synyed.net.proroc;




/**
 * redis协议解析器<br>
 * 
 * @Title: RedisProtocolDecoder.java
 * @Package com.wmz7year.synyed.net.proroc
 * @author jiangwei (ydswcy513@gmail.com)
 * @date 2015年12月10日 下午4:59:13
 * @version V1.0
 */
public class RedisProtocolDecoder extends CumulativeProtocolDecoder {

	/*
	 * @see org.apache.mina.filter.codec.CumulativeProtocolDecoder#doDecode(org.
	 * apache.mina.core.session.IoSession, org.apache.mina.core.buffer.IoBuffer,
	 * org.apache.mina.filter.codec.ProtocolDecoderOutput)
	 */
	@Override
	protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
		RedisProtocolParser parser = (RedisProtocolParser) session.getAttribute(REDIS_PROTOCOL_PARSER);
		// 将接收到的数据通过解析器解析为Redis数据包对象
		parser.read(in.buf());

		// 获取解析器解析出的数据包
		RedisPacket[] redisPackets = parser.getPackets();
		if (redisPackets != null) {
// Path: Redis-Synyed-common/src/main/java/com/wmz7year/synyed/constant/RedisProtocolConstant.java
// public static final String REDIS_PROTOCOL_PARSER = "redis_protpcol_parser";
// 
// Path: Redis-Synyed-common/src/main/java/com/wmz7year/synyed/packet/redis/RedisPacket.java
// public abstract class RedisPacket {
// 	/**
// 	 * redis命令
// 	 */
// 	protected String command;
// 
// 	public RedisPacket(String command) {
// 		this.command = command;
// 	}
// 
// 	public String getCommand() {
// 		return command;
// 	}
// 
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// 
// 	/**
// 	 * 获取数据包原始数据的方法
// 	 * 
// 	 * @return 数据包原始数据
// 	 */
// 	public abstract byte[] getData();
// }


// Path: Redis-Synyed-Agent/src/main/java/com/wmz7year/synyed/net/proroc/RedisProtocolDecoder.java
import static com.wmz7year.synyed.constant.RedisProtocolConstant.REDIS_PROTOCOL_PARSER;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import com.wmz7year.synyed.packet.redis.RedisPacket;

package com.wmz7year.synyed.net.proroc;




/**
 * redis协议解析器<br>
 * 
 * @Title: RedisProtocolDecoder.java
 * @Package com.wmz7year.synyed.net.proroc
 * @author jiangwei (ydswcy513@gmail.com)
 * @date 2015年12月10日 下午4:59:13
 * @version V1.0
 */
public class RedisProtocolDecoder extends CumulativeProtocolDecoder {

	/*
	 * @see org.apache.mina.filter.codec.CumulativeProtocolDecoder#doDecode(org.
	 * apache.mina.core.session.IoSession, org.apache.mina.core.buffer.IoBuffer,
	 * org.apache.mina.filter.codec.ProtocolDecoderOutput)
	 */
	@Override
	protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
		RedisProtocolParser parser = (RedisProtocolParser) session.getAttribute(REDIS_PROTOCOL_PARSER);
		// 将接收到的数据通过解析器解析为Redis数据包对象
		parser.read(in.buf());

		// 获取解析器解析出的数据包
		RedisPacket[] redisPackets = parser.getPackets();
		if (redisPackets != null) {
			for (RedisPacket redisPacket : redisPackets) {