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 and Type | Field and Description |
|---|---|
| private final TypeParameterMatcher | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | MessageToByteEncoder(Class<? extends I> outboundMessageType)
see |
| 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>
The type of messages to match outboundMessageType, boolean preferDirect)Create a new instance |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| protected ByteBuf | allocateBuffer(ChannelHandlerContext ctx, I msg, boolean preferDirect)
Allocate a |
| protected abstract void | encode(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToByteEncoder belongs tothe message to encode msg, ByteBuf the out)ByteBuf into which the encoded message will be writtenEncode a message into a |
| protected boolean | |
| public void | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg, ChannelPromise the promise)ChannelPromise to notify once the operation completesOverrides io. Implements io. ChannelHandlerContext#write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| matcher | back to summary |
|---|---|
| private final TypeParameterMatcher matcher | |
| preferDirect | back to summary |
|---|---|
| private final boolean preferDirect | |
| MessageToByteEncoder | back to summary |
|---|---|
| protected MessageToByteEncoder() see | |
| MessageToByteEncoder | back to summary |
|---|---|
| protected MessageToByteEncoder(Class<? extends I> outboundMessageType) see | |
| MessageToByteEncoder | back to summary |
|---|---|
| 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. | |
| MessageToByteEncoder | back to summary |
|---|---|
| protected MessageToByteEncoder(Class<? extends I> outboundMessageType, boolean preferDirect) Create a new instance | |
| acceptOutboundMessage | back to summary |
|---|---|
| public boolean acceptOutboundMessage(Object msg) throws Exception Returns | |
| allocateBuffer | back to summary |
|---|---|
| protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, I msg, boolean preferDirect) throws Exception Allocate a | |
| encode | back to summary |
|---|---|
| protected abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception Encode a message into a
| |
| isPreferDirect | back to summary |
|---|---|
| protected boolean isPreferDirect() | |
| write | back to summary |
|---|---|
| public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |