public abstract class MessageToMessageDecoder<I>
extends io.netty.channel.ChannelInboundHandlerAdapter
ChannelInboundHandlerAdapter
which decodes from one message to an other message.
For example here is an implementation which decodes a String
to an Integer
which represent
the length of the String
.
public class StringToIntegerDecoder extendsBe aware that you need to callMessageToMessageDecoder
<String
> {@Override
public void decode(ChannelHandlerContext
ctx,String
message, List<Object> out) throwsException
{ out.add(message.length()); } }
ReferenceCounted.retain()
on messages that are just passed through if they
are of type ReferenceCounted
. This is needed as the MessageToMessageDecoder
will call
ReferenceCounted.release()
on decoded messages.Modifier | Constructor and 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
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptInboundMessage(Object msg)
Returns
true if the given message should be handled. |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
protected abstract void |
decode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
List<Object> out)
Decode from one message to an other.
|
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
protected MessageToMessageDecoder()
public boolean acceptInboundMessage(Object msg) throws Exception
true
if the given message should be handled. If false
it will be passed to the next
ChannelInboundHandler
in the ChannelPipeline
.Exception
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
ctx
- the ChannelHandlerContext
which this MessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- the List
to which decoded messages should be addedException
- is thrown if an error occursCopyright © 2008–2019 The Netty Project. All rights reserved.