All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.yafeiwang124.common.tcp.protocol.codec.ProtocolEncoder Maven / Gradle / Ivy

package com.github.yafeiwang124.common.tcp.protocol.codec;

import com.github.yafeiwang124.common.tcp.protocol.MessageContext;
import com.github.yafeiwang1240.obrien.lang.Bytes;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class ProtocolEncoder extends MessageToByteEncoder {
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageContext msg, ByteBuf out) throws Exception {
        byte[] body = FstSerializer.encode(msg);
        byte[] header = Bytes.toBytes(body.length);
        out.writeBytes(header);
        out.writeBytes(body);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy