1. /*基于MessagePack的编码器,序列化*/
    2. public class MsgPackEncode extends MessageToByteEncoder<User> {
    3. @Override
    4. protected void encode(ChannelHandlerContext ctx, User msg, ByteBuf out)
    5. throws Exception {
    6. MessagePack messagePack = new MessagePack();
    7. byte[] raw = messagePack.write(msg);
    8. out.writeBytes(raw);
    9. }
    10. }