public abstract class ByteToMessageDecoder
extends io.netty.channel.ChannelInboundByteHandlerAdapter
ChannelInboundByteHandler which decodes bytes in a stream-like fashion from one ByteBuf to an other
Message type.
For example here is an implementation which reads all readable bytes from
the input ByteBuf and create a new ByteBuf.
public class SquareDecoder extends ByteToMessageDecoder {
@Override
public Object decode(ChannelHandlerContext ctx, ByteBuf in)
throws Exception {
return in.readBytes(in.readableBytes());
}
}
| Constructor and Description |
|---|
ByteToMessageDecoder() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
callDecode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelReadSuspended(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in)
Decode the from one
ByteBuf to an other. |
protected Object |
decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in)
Is called one last time when the
ChannelHandlerContext goes in-active. |
void |
inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in) |
boolean |
isSingleDecode()
If
true then only one message is decoded on each
ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelHandlerContext) call. |
void |
setSingleDecode(boolean singleDecode)
If set then only one message is decoded on each
ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelHandlerContext) call. |
discardInboundReadBytes, freeInboundBuffer, inboundBufferUpdated, newInboundBufferchannelActive, channelRegistered, channelUnregistered, userEventTriggeredafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaughtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic void setSingleDecode(boolean singleDecode)
ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelHandlerContext) call.
This may be useful if you need to do some protocol upgrade and want to make sure nothing is mixed up.
Default is false as this has performance impacts.public boolean isSingleDecode()
true then only one message is decoded on each
ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelHandlerContext) call.
Default is false as this has performance impacts.public void inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in)
throws Exception
inboundBufferUpdated in class io.netty.channel.ChannelInboundByteHandlerAdapterExceptionpublic void channelReadSuspended(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelReadSuspended in interface io.netty.channel.ChannelStateHandlerchannelReadSuspended in class io.netty.channel.ChannelStateHandlerAdapterExceptionpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive in interface io.netty.channel.ChannelStateHandlerchannelInactive in class io.netty.channel.ChannelStateHandlerAdapterExceptionprotected void callDecode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in)
protected abstract Object decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in) throws Exception
ByteBuf to an other. This method will be called till either the input
ByteBuf has nothing to read anymore, till nothing was read from the input ByteBuf or till
this method returns null.ctx - the ChannelHandlerContext which this ByteToByteDecoder belongs toin - the ByteBuf from which to read dataByteBuf was decoded, or null if
there was not enough data left in the ByteBuf to decode.Exception - is thrown if an error accourprotected Object decodeLast(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in) throws Exception
ChannelHandlerContext goes in-active. Which means the
channelInactive(ChannelHandlerContext) was triggered.
By default this will just call decode(ChannelHandlerContext, ByteBuf) but sub-classes may
override this for some special cleanup operation.ExceptionCopyright © 2008-2013 The Netty Project. All Rights Reserved.