- 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
ChannelHandler
which decodes from one message to another message. For example here is an implementation which decodes aString
to anInteger
which represent the length of theString
.{@code public class StringToIntegerDecoder extends MessageToMessageDecoder
{
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
MessageToMessageDecoder(Class<? extends I> inboundMessageType)
Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptInboundMessage(Object msg)
Returnstrue
if the given message should be handled.void
channelRead(ChannelHandlerContext ctx, Object msg)
Invoked when the currentChannel
has read a message from the peer.protected void
decode(ChannelHandlerContext ctx, I msg)
Decode from one message to another.protected void
decodeAndClose(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
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelHandler
in theChannelPipeline
.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandler
Invoked when the currentChannel
has 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
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs 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
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to another one- Throws:
Exception
- is thrown if an error occurs
-
-