- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageEncoder<I>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
Base64Encoder,ByteArrayEncoder,DatagramDnsQueryEncoder,DatagramDnsResponseEncoder,DatagramPacketEncoder,HttpObjectEncoder,LengthFieldPrepender,LineEncoder,StringEncoder,TcpDnsResponseEncoder,WebSocket13FrameEncoder,WebSocketExtensionEncoder
public abstract class MessageToMessageEncoder<I> extends ChannelHandlerAdapter
ChannelHandlerwhich encodes from one message to another message For example here is an implementation which decodes anIntegerto anString.{@code public class IntegerToStringEncoder extends MessageToMessageEncoder{
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMessageToMessageEncoder()Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedMessageToMessageEncoder(Class<? extends I> outboundMessageType)Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptOutboundMessage(Object msg)Returnstrueif the given message should be handled.protected voidencode(ChannelHandlerContext ctx, I msg, List<Object> out)Encode from one message to another.protected voidencodeAndClose(ChannelHandlerContext ctx, I msg, List<Object> out)Encode from one message to another.Future<Void>write(ChannelHandlerContext ctx, Object msg)Called once a write operation is made.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
acceptOutboundMessage
public boolean acceptOutboundMessage(Object msg) throws Exception
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelHandlerin theChannelPipeline.- Throws:
Exception
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called.- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to write- Returns:
- the
Futurewhich will be notified once the operation completes.
-
encode
protected void encode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
Encode from one message to another. This method will be called for each written message that can be handled by this encoder.The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
encodeAndClose(ChannelHandlerContext, Object, List)method.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageEncoderbelongs to.msg- the message to encode to another one.out- theListinto which produced output messages should be added.- Throws:
Exception- is thrown if an error occurs.
-
encodeAndClose
protected void encodeAndClose(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
Encode from one message to another. This method will be called for each written message that can be handled by this encoder.The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
encode(ChannelHandlerContext, Object, List)method.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageEncoderbelongs to.msg- the message to encode to another one.out- theListinto which produced output messages should be added.- Throws:
Exception- is thrown if an error occurs.
-
-