public abstract class ByteToMessageDecoder extends 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 extendsByteToMessageDecoder
{@Override
publicObject
decode(ChannelHandlerContext
ctx,ByteBuf
in) throwsException
{ return in.readBytes(in.readableBytes()); } }
ChannelHandler.Sharable
Constructor and Description |
---|
ByteToMessageDecoder() |
discardInboundReadBytes, freeInboundBuffer, inboundBufferUpdated, newInboundBuffer
channelActive, channelRegistered, channelUnregistered, userEventTriggered
afterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
channelActive, channelRegistered, channelUnregistered, userEventTriggered
afterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught
public 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(ChannelHandlerContext ctx, ByteBuf in) throws Exception
ChannelInboundByteHandlerAdapter
ByteBuf
received more data to read. What will be done
with the data at this point is up to the implementation.
Implementations may choose to read it or just let it in the buffer to read it later.inboundBufferUpdated
in class ChannelInboundByteHandlerAdapter
Exception
public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception
ChannelStateHandlerAdapter
ChannelHandlerContext.fireChannelReadSuspended()
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelReadSuspended
in interface ChannelStateHandler
channelReadSuspended
in class ChannelStateHandlerAdapter
Exception
public void channelInactive(ChannelHandlerContext ctx) throws Exception
ChannelStateHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelStateHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
in interface ChannelStateHandler
channelInactive
in class ChannelStateHandlerAdapter
Exception
protected void callDecode(ChannelHandlerContext ctx, ByteBuf in)
protected abstract Object decode(ChannelHandlerContext ctx, 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(ChannelHandlerContext ctx, 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.Exception
Copyright © 2008-2013 The Netty Project. All Rights Reserved.