@ChannelHandler.Sharable public class LengthFieldPrepender extends MessageToMessageEncoder<ByteBuf>
For example, LengthFieldPrepender(2) will encode the
following 12-bytes string:
+----------------+ | "HELLO, WORLD" | +----------------+into the following:
+--------+----------------+ + 0x000C | "HELLO, WORLD" | +--------+----------------+If you turned on the
lengthIncludesLengthFieldLength flag in the
constructor, the encoded data would look like the following
(12 (original data) + 2 (prepended data) = 14 (0xE)):
+--------+----------------+ + 0x000E | "HELLO, WORLD" | +--------+----------------+
ChannelHandler.Sharable| 构造器和说明 |
|---|
LengthFieldPrepender(java.nio.ByteOrder byteOrder,
int lengthFieldLength,
int lengthAdjustment,
boolean lengthIncludesLengthFieldLength)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength,
boolean lengthIncludesLengthFieldLength)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength,
int lengthAdjustment)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength,
int lengthAdjustment,
boolean lengthIncludesLengthFieldLength)
Creates a new instance.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf msg,
java.util.List<java.lang.Object> out)
Encode from one message to an other.
|
acceptOutboundMessage, writebind, close, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerAdded, handlerRemovedpublic LengthFieldPrepender(int lengthFieldLength)
lengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.java.lang.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8public LengthFieldPrepender(int lengthFieldLength,
boolean lengthIncludesLengthFieldLength)
lengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.lengthIncludesLengthFieldLength - if true, the length of the prepended
length field is added to the value of the
prepended length field.java.lang.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8public LengthFieldPrepender(int lengthFieldLength,
int lengthAdjustment)
lengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.lengthAdjustment - the compensation value to add to the value
of the length fieldjava.lang.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8public LengthFieldPrepender(int lengthFieldLength,
int lengthAdjustment,
boolean lengthIncludesLengthFieldLength)
lengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.lengthAdjustment - the compensation value to add to the value
of the length fieldlengthIncludesLengthFieldLength - if true, the length of the prepended
length field is added to the value of the
prepended length field.java.lang.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8public LengthFieldPrepender(java.nio.ByteOrder byteOrder,
int lengthFieldLength,
int lengthAdjustment,
boolean lengthIncludesLengthFieldLength)
byteOrder - the ByteOrder of the length fieldlengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.lengthAdjustment - the compensation value to add to the value
of the length fieldlengthIncludesLengthFieldLength - if true, the length of the prepended
length field is added to the value of the
prepended length field.java.lang.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8protected void encode(ChannelHandlerContext ctx, ByteBuf msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageEncoderencode 在类中 MessageToMessageEncoder<ByteBuf>ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs tomsg - the message to encode to an other oneout - the List into which the encoded msg should be added
needs to do some kind of aggregationjava.lang.Exception - is thrown if an error occurs