@ChannelHandler.Sharable public class LengthFieldPrepender extends MessageToMessageEncoder<ByteBuf>
例如, LengthFieldPrepender
(2)将编码以下12个字节的字符串:
+----------------+
| "HELLO, WORLD" |
+----------------+
分成以下几部分:
+--------+----------------+
+ 0x000C | "HELLO, WORLD" |
+--------+----------------+
如果您在构造函数中打开了lengthIncludesLengthFieldLength
标志,则编码数据将如下所示(12(原始数据)+ 2(前置数据)= 14(0xE)):
+--------+----------------+
+ 0x000E | "HELLO, WORLD" |
+--------+----------------+
ChannelHandler.Sharable
Constructor and Description |
---|
LengthFieldPrepender(java.nio.ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)
创建一个新的实例。
|
LengthFieldPrepender(int lengthFieldLength)
创建一个新的实例。
|
LengthFieldPrepender(int lengthFieldLength, boolean lengthIncludesLengthFieldLength)
创建一个新的实例。
|
LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment)
创建一个新的实例。
|
LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)
创建一个新的实例。
|
Modifier and Type | Method and Description |
---|---|
protected void |
encode(ChannelHandlerContext ctx, ByteBuf msg, java.util.List<java.lang.Object> out)
从一条消息编码到另一条消息。
|
acceptOutboundMessage, write
bind, close, connect, deregister, disconnect, flush, read
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
public LengthFieldPrepender(int lengthFieldLength)
lengthFieldLength
- 前置长度字段的长度。
只允许1,2,3,4和8。
java.lang.IllegalArgumentException
-如果
lengthFieldLength
不为1,2,3,4,或8
public LengthFieldPrepender(int lengthFieldLength, boolean lengthIncludesLengthFieldLength)
lengthFieldLength
- 前置长度字段的长度。
只允许1,2,3,4和8。
lengthIncludesLengthFieldLength
- 如果是
true
,则将前置长度字段的长度添加到前置长度字段的值中。
java.lang.IllegalArgumentException
-如果
lengthFieldLength
不为1,2,3,4,或8
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment)
lengthFieldLength
- 前置长度字段的长度。
只允许1,2,3,4和8。
lengthAdjustment
- 要添加到长度字段值的补偿值
java.lang.IllegalArgumentException
-如果
lengthFieldLength
不为1,2,3,4,或8
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)
lengthFieldLength
- 前置长度字段的长度。
只允许1,2,3,4和8。
lengthAdjustment
- 要添加到长度字段值的补偿值
lengthIncludesLengthFieldLength
- 如果是
true
,则将前置长度字段的长度添加到前置长度字段的值中。
java.lang.IllegalArgumentException
-如果
lengthFieldLength
不为1,2,3,4,或8
public LengthFieldPrepender(java.nio.ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)
byteOrder
- 长度字段的
ByteOrder
lengthFieldLength
- 前置长度字段的长度。
只允许1,2,3,4和8。
lengthAdjustment
- 要添加到长度字段值的补偿值
lengthIncludesLengthFieldLength
- 如果
true
,前置长度字段的长度被添加到前置长度字段的值。
java.lang.IllegalArgumentException
-如果
lengthFieldLength
不为1,2,3,4,或8
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageEncoder
encode
在课程
MessageToMessageEncoder<ByteBuf>
ctx
- MessageToMessageEncoder
属于的ChannelHandlerContext
msg
- 要编码到另一个的消息
out
- 应该添加编码味精的
List
需要做某种聚合
java.lang.Exception
- is thrown if an error occurs
Copyright © 2008–2018 The Netty Project. All rights reserved.