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

org.zhongweixian.decode.MessageEncoder Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
package org.zhongweixian.decode;

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

/**
 * Created by caoliang on 2020-02-25
 */
public class MessageEncoder extends MessageToByteEncoder {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, String s, ByteBuf byteBuf) throws Exception {
        byte[] bytes = s.getBytes();
        byteBuf.writeInt(4 + bytes.length);
        byteBuf.writeBytes(bytes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy