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
构造器和说明 |
---|
FixedLengthFrameDecoder(int frameLength)
Calls
FixedLengthFrameDecoder(int, boolean) with false |
FixedLengthFrameDecoder(int frameLength,
boolean allocateFullBuffer)
Creates a new instance.
|
限定符和类型 | 方法和说明 |
---|---|
protected java.lang.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 java.lang.Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws java.lang.Exception
FrameDecoder
FrameDecoder.extractFrame(ChannelBuffer, int, int)
method,
to make optimizations easier later.decode
在类中 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.java.lang.Exception
protected ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity)
FrameDecoder
ChannelBuffer
which is used for the cumulation.
Sub-classes may override this.newCumulationBuffer
在类中 FrameDecoder
ctx
- ChannelHandlerContext
for this handlerChannelBuffer
which is used for cumulation