org.bcos.channel.handler.Encoder Maven / Gradle / Ivy
package org.bcos.channel.handler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
public class Encoder extends MessageToByteEncoder {
private static Logger logger = LoggerFactory.getLogger(Encoder.class);
@Override
protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception {
logger.debug("encode:" + msg.getLength() + "," + msg.getData());
out.writeIntLE(msg.getLength());
out.writeShortLE(msg.getType());
out.writeBytes(msg.getData());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy