public abstract class MessageToByteEncoder<I> extends 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);
}
}
ChannelHandler.Sharable| Modifier | Constructor and Description |
|---|---|
protected |
MessageToByteEncoder()
see
MessageToByteEncoder(boolean) with true as boolean parameter. |
protected |
MessageToByteEncoder(boolean preferDirect)
Create a new instance which will try to detect the types to match out of the type parameter of the class.
|
protected |
MessageToByteEncoder(Class<? extends I> outboundMessageType)
see
MessageToByteEncoder(Class, boolean) with true as boolean value. |
protected |
MessageToByteEncoder(Class<? extends I> outboundMessageType,
boolean preferDirect)
Create a new instance
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(Object msg)
Returns
true if the given message should be handled. |
protected ByteBuf |
allocateBuffer(ChannelHandlerContext ctx,
I msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf). |
protected abstract void |
encode(ChannelHandlerContext ctx,
I msg,
ByteBuf out)
Encode a message into a
ByteBuf. |
protected boolean |
isPreferDirect() |
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
bind, close, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerAdded, handlerRemovedprotected MessageToByteEncoder()
MessageToByteEncoder(boolean) with true as boolean parameter.protected MessageToByteEncoder(Class<? extends I> outboundMessageType)
MessageToByteEncoder(Class, boolean) with true as boolean value.protected MessageToByteEncoder(boolean preferDirect)
public boolean acceptOutboundMessage(Object msg) throws Exception
true if the given message should be handled. If false it will be passed to the next
ChannelOutboundHandler in the ChannelPipeline.Exceptionpublic void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapter