package com.pwt.netty.handler.codec.charger;

import com.pwt.netty.common.charger.ChargerMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

/**
 * 消息封装成帧
 */
public class ChargerProtocolEncoder extends MessageToMessageEncoder<ChargerMessage<?>> {

    @Override
    protected void encode(ChannelHandlerContext ctx, ChargerMessage<?> msg, List<Object> out) throws Exception {
        ByteBuf buffer = ctx.alloc().buffer();
        msg.encode(buffer);
        out.add(buffer);
    }
}
