public abstract class MessageToByteEncoder<I>
extends io.netty.channel.ChannelOutboundHandlerAdapter
ChannelOutboundHandlerAdapter which encodes message in a stream-like fashion from one message to an
ByteBuf.
Example implementation which encodes Integers to a ByteBuf.
public class IntegerEncoder extends MessageToByteEncoder<Integer> {
@Override
public void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out)
throws Exception {
out.writeInt(msg);
}
}
| Modifier | Constructor and Description |
|---|---|
protected |
MessageToByteEncoder() |
protected |
MessageToByteEncoder(boolean preferDirect) |
protected |
MessageToByteEncoder(Class<? extends I> outboundMessageType) |
protected |
MessageToByteEncoder(Class<? extends I> outboundMessageType,
boolean preferDirect) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(Object msg) |
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.buffer.ByteBuf out)
Encode a message into a
ByteBuf. |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs,
io.netty.channel.ChannelPromise promise) |
bind, close, connect, deregister, disconnect, readexceptionCaught, handlerAdded, handlerRemovedprotected MessageToByteEncoder()
protected MessageToByteEncoder(boolean preferDirect)
public boolean acceptOutboundMessage(Object msg) throws Exception
Exceptionpublic void write(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs,
io.netty.channel.ChannelPromise promise)
throws Exception
write in interface io.netty.channel.ChannelOutboundHandlerwrite in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionprotected abstract void encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.buffer.ByteBuf out)
throws Exception
ByteBuf. This method will be called till the MessageList has
nothing left.ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs tomsg - the message to encodeout - the ByteBuf into which the encoded message will be writtenException - is thrown if an error accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.