public class FixedLengthFrameDecoder extends FrameDecoder
ChannelBuffer
s by the fixed number
of bytes. For example, if you received the following four fragmented packets:
+---+----+------+----+ | A | BC | DEFG | HI | +---+----+------+----+A
FixedLengthFrameDecoder
(3)
will decode them into the
following three packets with the fixed length:
+-----+-----+-----+ | ABC | DEF | GHI | +-----+-----+-----+
ChannelHandler.Sharable
cumulation, DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
Constructor and Description |
---|
FixedLengthFrameDecoder(int frameLength)
Calls
FixedLengthFrameDecoder(int, boolean) with false |
FixedLengthFrameDecoder(int frameLength,
boolean allocateFullBuffer)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
decode(ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buffer)
Decodes the received packets so far into a frame.
|
protected ChannelBuffer |
newCumulationBuffer(ChannelHandlerContext ctx,
int minimumCapacity)
Create a new
ChannelBuffer which is used for the cumulation. |
actualReadableBytes, afterAdd, afterRemove, appendToCumulation, beforeAdd, beforeRemove, channelClosed, channelDisconnected, cleanup, decodeLast, exceptionCaught, extractFrame, getMaxCumulationBufferCapacity, getMaxCumulationBufferComponents, internalBuffer, isUnfold, messageReceived, replace, setMaxCumulationBufferCapacity, setMaxCumulationBufferComponents, setUnfold, unfoldAndFireMessageReceived, updateCumulation
channelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeComplete
public FixedLengthFrameDecoder(int frameLength)
FixedLengthFrameDecoder(int, boolean)
with false
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer)
frameLength
- the length of the frameallocateFullBuffer
- true
if the cumulative ChannelBuffer
should use the
frameLength
as its initial sizeprotected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception
FrameDecoder
FrameDecoder.extractFrame(ChannelBuffer, int, int)
method,
to make optimizations easier later.decode
in class FrameDecoder
ctx
- the context of this handlerchannel
- the current channelbuffer
- the cumulative buffer of received packets so far.
Note that the buffer might be empty, which means you
should not make an assumption that the buffer contains
at least one byte in your decoder implementation.null
if there's not enough data in the buffer to decode a frame.Exception
protected ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity)
FrameDecoder
ChannelBuffer
which is used for the cumulation.
Sub-classes may override this.newCumulationBuffer
in class FrameDecoder
ctx
- ChannelHandlerContext
for this handlerChannelBuffer
which is used for cumulationCopyright © 2008-2014 The Netty Project. All Rights Reserved.