Top Description Fields Constructors Methods
io.netty.handler.codec

public abstract Class MessageToMessageDecoder<I>

extends ChannelInboundHandlerAdapter
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.base64.Base64Decoder, io.netty.handler.codec.bytes.ByteArrayDecoder, io.netty.handler.codec.protobuf.ProtobufDecoder, io.netty.handler.codec.protobuf.ProtobufDecoderNano, io.netty.handler.codec.string.StringDecoder, io.netty.handler.codec.DatagramPacketDecoder, io.netty.handler.codec.MessageAggregator
Imports
io.netty.channel.ChannelHandlerContext, .ChannelInboundHandler, .ChannelInboundHandlerAdapter, .ChannelPipeline, io.netty.util.ReferenceCountUtil, .ReferenceCounted, io.netty.util.internal.TypeParameterMatcher, java.util.List

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 extends
            MessageToMessageDecoder<String> {

        @Override
        public void decode(ChannelHandlerContext ctx, String message,
                           List<Object> out) throws Exception {
            out.add(message.length());
        }
    }
Be aware that you need to call 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.

Field Summary

Modifier and TypeField and Description
private final TypeParameterMatcher

Constructor Summary

AccessConstructor 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>
The type of messages to match and so decode
inboundMessageType
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptInboundMessage(Object msg)

Returns true if the given message should be handled.

public void
protected abstract void
decode(ChannelHandlerContext ctx, I
the message to decode to an other one
msg
,
List<Object>
the List to which decoded messages should be added
out
)

Decode from one message to an other.

Inherited from io.netty.channel.ChannelInboundHandlerAdapter:
channelActivechannelInactivechannelReadCompletechannelRegisteredchannelUnregisteredchannelWritabilityChangedexceptionCaughtuserEventTriggered

Field Detail

matcherback to summary
private final TypeParameterMatcher matcher

Constructor Detail

MessageToMessageDecoderback to summary
protected MessageToMessageDecoder()

Create a new instance which will try to detect the types to match out of the type parameter of the class.

MessageToMessageDecoderback to summary
protected MessageToMessageDecoder(Class<? extends I> inboundMessageType)

Create a new instance

Parameters
inboundMessageType:Class<? extends I>

The type of messages to match and so decode

Method Detail

acceptInboundMessageback to summary
public boolean acceptInboundMessage(Object msg) throws Exception

Returns true if the given message should be handled. If false it will be passed to the next ChannelInboundHandler in the ChannelPipeline.

channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
decodeback to summary
protected abstract void decode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception

Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:I

the message to decode to an other one

out:List<Object>

the List to which decoded messages should be added

Exceptions
Exception:
is thrown if an error occurs