public class FixedLengthFrameDecoder extends ByteToMessageDecoder
ByteBuf
分割成固定的字节数。
例如,如果您收到以下四个分段数据包:
+---+----+------+----+
| A | BC | DEFG | HI |
+---+----+------+----+
A FixedLengthFrameDecoder
(3)
会将它们解码为以下三个固定长度的数据包:
+-----+-----+-----+
| ABC | DEF | GHI |
+-----+-----+-----+
ByteToMessageDecoder.Cumulator
ChannelHandler.Sharable
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
Constructor and Description |
---|
FixedLengthFrameDecoder(int frameLength)
创建一个新的实例。
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
decode(ChannelHandlerContext ctx, ByteBuf in)
从 ByteBuf 中创建一个框架并将其返回。
|
protected void |
decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
解码从一个 ByteBuf 到另一个。
|
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
ensureNotSharable, handlerAdded, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded
public FixedLengthFrameDecoder(int frameLength)
frameLength
- 框架的长度
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
ByteToMessageDecoder
decode
ByteToMessageDecoder
ctx
- 这ByteToMessageDecoder
所属的ChannelHandlerContext
in
- 从中读取数据的ByteBuf
out
- 应该添加解码消息的
List
java.lang.Exception
- 发生错误时抛出
protected java.lang.Object decode(ChannelHandlerContext ctx, ByteBuf in) throws java.lang.Exception
ByteBuf
中创建一个框架并将其返回。
ctx
- 这ByteToMessageDecoder
所属的ChannelHandlerContext
in
- 从中读取数据的ByteBuf
ByteBuf
表示帧或null
。
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.