解码器
/**
-
@param ctx 上下文
-
@param msg 需要解码的数据
-
@param out 解码列表
*/
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception {
final byte[] array;
final int length = msg.readableBytes();
array = new byte[length];
// 获取需要解码的字节数组
msg.getBytes(msg.readerIndex(), array,0,length);
MessagePack msgpack = new MessagePack();
// 反序列化并将结果保存到了解码列表中
out.add(msgpack.read(array));
}
[](()3.客户端
EchoClient
/**
-
MsgPack 编解码器
-
@author 波波烤鸭
-
@email dengpbs@163.com
*/
public class EchoClient {
public static void main(String[] args) throws Exception {
int port = 8080;<