package com.yfd.platform.component.nettyserver;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MyMessageEncoder extends MessageToByteEncoder<MyMessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, MyMessageProtocol msg, ByteBuf out) throws Exception {
        //TCP传输应用协议定义
        byte[] flag=new byte[]{(byte) 0xEB, (byte) 0x90};
        out.writeBytes(flag);
        out.writeLongLE(msg.getSenderSerialNo());
        out.writeLongLE(msg.getReceiverSerialNo());
        out.writeByte(msg.getSessionflag());
        out.writeIntLE(msg.getXmllen());
        out.writeBytes(msg.getXmlcontent());
        out.writeBytes(flag);
    }
}

