- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<I>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
Base64Decoder,ByteArrayDecoder,DatagramDnsQueryDecoder,DatagramDnsResponseDecoder,DatagramPacketDecoder,HttpContentDecoder,MessageAggregator,StringDecoder,WebSocketClientProtocolHandler,WebSocketExtensionDecoder,WebSocketServerProtocolHandler
public abstract class MessageToMessageDecoder<I> extends ChannelHandlerAdapter
ChannelHandlerwhich decodes from one message to another message. For example here is an implementation which decodes aStringto anIntegerwhich represent the length of theString.{@code public class StringToIntegerDecoder extends MessageToMessageDecoder{
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMessageToMessageDecoder()Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedMessageToMessageDecoder(Class<? extends I> inboundMessageType)Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptInboundMessage(Object msg)Returnstrueif the given message should be handled.voidchannelRead(ChannelHandlerContext ctx, Object msg)Invoked when the currentChannelhas read a message from the peer.protected voiddecode(ChannelHandlerContext ctx, I msg)Decode from one message to another.protected voiddecodeAndClose(ChannelHandlerContext ctx, I msg)Decode from one message to another.-
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, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(Object msg) throws Exception
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelHandlerin theChannelPipeline.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandlerInvoked when the currentChannelhas read a message from the peer.- Throws:
Exception
-
decode
protected void decode(ChannelHandlerContext ctx, I msg) throws Exception
Decode from one message to another. This method will be called for each written message that can be handled by this decoder.The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
decodeAndClose(ChannelHandlerContext, Object)method.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs tomsg- the message to decode to another one- Throws:
Exception- is thrown if an error occurs
-
decodeAndClose
protected void decodeAndClose(ChannelHandlerContext ctx, I msg) throws Exception
Decode from one message to another. This method will be called for each written message that can be handled by this decoder.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
decodeAndClose(ChannelHandlerContext, Object)method.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs tomsg- the message to decode to another one- Throws:
Exception- is thrown if an error occurs
-
-