12345678910111213141516 |
- package cn.com.zyjblogs.chat.netty;
- import io.netty.buffer.ByteBuf;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.handler.codec.MessageToByteEncoder;
- public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {
- @Override
- protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
- System.out.println("\nMyMessageEncoder方法被调用 编码");
- out.writeInt(msg.getLen());
- out.writeBytes(msg.getContent());
- }
- }
|