org.zhongweixian.decode.MessageEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of websocket-api Show documentation
Show all versions of websocket-api Show documentation
Demo project for netty-api
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