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" | +--------+----------------+
| Modifier and Type | Field and Description |
|---|---|
| private final ByteOrder | |
| private final int | |
| private final int | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| public | LengthFieldPrepender(int
the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are supported by default. lengthFieldLength)Creates a new instance. |
| public | LengthFieldPrepender(int
the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are supported by default. lengthFieldLength, boolean if lengthIncludesLengthFieldLength)true, the length of the prepended
length field is added to the value of the
prepended length field.Creates a new instance. |
| public | LengthFieldPrepender(int
the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are supported by default. lengthFieldLength, int the compensation value to add to the value
of the length field lengthAdjustment)Creates a new instance. |
| public | LengthFieldPrepender(int
the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are supported by default. lengthFieldLength, int the compensation value to add to the value
of the length field lengthAdjustment, boolean if lengthIncludesLengthFieldLength)true, the length of the prepended
length field is added to the value of the
prepended length field.Creates a new instance. |
| public | LengthFieldPrepender(ByteOrder
the byteOrder, int ByteOrder of the length fieldthe length of the prepended length field.
Only 1, 2, 3, 4, and 8 are supported by default. lengthFieldLength, int the compensation value to add to the value
of the length field lengthAdjustment, boolean if lengthIncludesLengthFieldLength)true, the length of the prepended
length field is added to the value of the
prepended length field.Creates a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | encode(ChannelHandlerContext
the ctx, Buffer ChannelHandlerContext which this MessageToMessageEncoder belongs to.the message to encode to another one. buffer, List<Object> the out)List into which produced output messages should be added.Overrides io. |
| protected Buffer | Returns: A buffer containing the encoded lengththe ctx, int ChannelHandlerContext which this LengthFieldPrepender belongs tothe length which should be encoded in the length field length, int the length of the prepended length field lengthFieldLength, ByteOrder the byteOrder)ByteOrder of the length fieldEncodes the length into a buffer which will be prepended as the length field. |
| public boolean | isSharable()
Overrides default io. true if this handler is sharable and thus can be added
to more than one ChannelPipeline.
|
| byteOrder | back to summary |
|---|---|
| private final ByteOrder byteOrder | |
| lengthAdjustment | back to summary |
|---|---|
| private final int lengthAdjustment | |
| lengthFieldLength | back to summary |
|---|---|
| private final int lengthFieldLength | |
| lengthIncludesLengthFieldLength | back to summary |
|---|---|
| private final boolean lengthIncludesLengthFieldLength | |
| LengthFieldPrepender | back to summary |
|---|---|
| public LengthFieldPrepender(int lengthFieldLength) Creates a new instance.
| |
| LengthFieldPrepender | back to summary |
|---|---|
| public LengthFieldPrepender(int lengthFieldLength, boolean lengthIncludesLengthFieldLength) Creates a new instance.
| |
| LengthFieldPrepender | back to summary |
|---|---|
| public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment) Creates a new instance.
| |
| LengthFieldPrepender | back to summary |
|---|---|
| public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength) Creates a new instance.
| |
| LengthFieldPrepender | back to summary |
|---|---|
| public LengthFieldPrepender(ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength) Creates a new instance.
| |
| encode | back to summary |
|---|---|
| protected void encode(ChannelHandlerContext ctx, Buffer buffer, List<Object> out) throws Exception Overrides io. Doc from io. Encode from one message to another. This method will be called for each written message that can be handled by this encoder. The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
| |
| getLengthFieldBuffer | back to summary |
|---|---|
| protected Buffer getLengthFieldBuffer(ChannelHandlerContext ctx, int length, int lengthFieldLength, ByteOrder byteOrder) Encodes the length into a buffer which will be prepended as the length field. The default implementation is capable of encoding the length into an 8/16/24/32/64 bit integer. Override this method to encode the length field differently.
| |
| isSharable | back to summary |
|---|---|
| public boolean isSharable() Overrides default io. Doc from io. Returns
| |