@@ -0,0 +1,1959 @@
+/**%0A * %0A */%0Apackage cn.strong.fastdfs.client.handler;%0A%0Aimport static cn.strong.fastdfs.client.CommandCodes.FDFS_PROTO_CMD_RESP;%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.channel.ChannelHandlerContext;%0Aimport io.netty.handler.codec.ReplayingDecoder;%0A%0Aimport java.util.List;%0A%0Aimport cn.strong.fastdfs.client.Consts;%0Aimport cn.strong.fastdfs.client.protocol.response.Receiver;%0Aimport cn.strong.fastdfs.ex.FastdfsException;%0A%0A/**%0A * FastDFS %E5%93%8D%E5%BA%94%E8%A7%A3%E7%A0%81%E5%99%A8%0A * %0A * @author liulongbiao%0A *%0A */%0Apublic class FastdfsDecoder extends ReplayingDecoder%3CVoid%3E %7B%0A%0A%09private boolean head = true;%0A%0A%09@Override%0A%09protected void decode(ChannelHandlerContext ctx, ByteBuf in, List%3CObject%3E out) throws Exception %7B%0A%09%09if (head) %7B%0A%09%09%09readHead(ctx, in);%0A%09%09%7D else %7B%0A%09%09%09readContent(ctx, in);%0A%09%09%7D%0A%09%7D%0A%0A%09private void readHead(ChannelHandlerContext ctx, ByteBuf in) %7B%0A%09%09long length = in.readLong();%0A%09%09byte cmd = in.readByte();%0A%09%09byte errno = in.readByte();%0A%09%09if (errno != Consts.ERRNO_OK) %7B%0A%09%09%09throw new FastdfsException(%22Fastdfs responsed with an error, errno is %22 + errno);%0A%09%09%7D%0A%09%09if (cmd != FDFS_PROTO_CMD_RESP) %7B%0A%09%09%09throw new FastdfsException(%22Expect response command code error : %22 + cmd);%0A%09%09%7D%0A%0A%09%09Receiver receiver = ensureGetReceiver(ctx);%0A%09%09long expectLength = receiver.expectLength();%0A%09%09if (expectLength %3E= 0) %7B%0A%09%09%09if (length != expectLength) %7B%0A%09%09%09%09throw new FastdfsException(%22Expect response length : %22 + expectLength%0A%09%09%09%09%09%09+ %22 , but receive length : %22 + length);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09receiver.setLength(length);%0A%0A%09%09head = false;%0A%09%09checkpoint();%0A%09%7D%0A%0A%09private Receiver ensureGetReceiver(ChannelHandlerContext ctx) %7B%0A%09%09Receiver resp = ctx.channel().attr(Receiver.RECEIVER).get();%0A%09%09if (resp == null) %7B%0A%09%09%09throw new FastdfsException(%22Receiver is not exist in channel%22);%0A%09%09%7D%0A%09%09return resp;%0A%09%7D%0A%0A%09private void readContent(ChannelHandlerContext ctx, ByteBuf in) %7B%0A%09%09Receiver receiver = ensureGetReceiver(ctx);%0A%09%09boolean ended = receiver.tryRead(in);%0A%09%09if (ended) %7B%0A%09%09%09head = true;%0A%09%09%7D%0A%09%09checkpoint();%0A%09%7D%0A%0A%7D%0A

implement FastdfsDecoder