ByteToMessageCodecHandler.java
661 Bytes
package com.viontech.netty;
import com.viontech.model.BaseModel;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2020/8/21
*/
public class ByteToMessageCodecHandler extends ByteToMessageCodec<BaseModel> {
@Override
protected void encode(ChannelHandlerContext ctx, BaseModel msg, ByteBuf out) throws Exception {
msg.to(out);
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
out.add(BaseModel.from(in));
}
}