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 extendsByteToMessageDecoder
{@Override
public void decode(ChannelHandlerContext
ctx,ByteBuf
in,MessageBuf
out) throwsException
{ out.add(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 void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.MessageBuf<Object> out)
Decode the from one
ByteBuf to an other. |
protected void |
decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.MessageBuf<Object> out)
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, inboundBufferUpdated, newInboundBuffer
channelActive, channelRegistered, channelUnregistered, userEventTriggered
exceptionCaught, handlerAdded, handlerRemoved
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in) throws Exception
inboundBufferUpdated
in class io.netty.channel.ChannelInboundByteHandlerAdapter
Exception
public void channelReadSuspended(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelReadSuspended
in interface io.netty.channel.ChannelStateHandler
channelReadSuspended
in class io.netty.channel.ChannelStateHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelStateHandler
channelInactive
in class io.netty.channel.ChannelStateHandlerAdapter
Exception
protected void callDecode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.MessageBuf<Object> out) 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 dataout
- the MessageBuf
to which decoded messages should be addedException
- is thrown if an error accourprotected void decodeLast(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.MessageBuf<Object> out) throws Exception
ChannelHandlerContext
goes in-active. Which means the
channelInactive(ChannelHandlerContext)
was triggered.
By default this will just call decode(ChannelHandlerContext, ByteBuf, MessageBuf)
but sub-classes may
override this for some special cleanup operation.Exception
Copyright © 2008-2013 The Netty Project. All Rights Reserved.