Top Description Fields Constructors Methods
io.netty.handler.codec

public Class LengthFieldPrepender

extends MessageToMessageEncoder<ByteBuf>
Class Inheritance
Annotations
@Sharable
Static Imports
io.netty.util.internal.ObjectUtil.checkPositiveOrZero

An encoder that prepends the length of the message. The length value is prepended as a binary form.

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" |
+--------+----------------+

Field Summary

Modifier and TypeField and Description
private final ByteOrder
private final int
private final int
private final boolean

Constructor Summary

AccessConstructor and Description
public
LengthFieldPrepender(int
the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.
lengthFieldLength
)

Creates a new instance.

public
LengthFieldPrepender(int
the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.
lengthFieldLength
,
boolean
if true, the length of the prepended length field is added to the value of the prepended length field.
lengthIncludesLengthFieldLength
)

Creates a new instance.

public
LengthFieldPrepender(int
the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.
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 allowed.
lengthFieldLength
,
int
the compensation value to add to the value of the length field
lengthAdjustment
,
boolean
if true, the length of the prepended length field is added to the value of the prepended length field.
lengthIncludesLengthFieldLength
)

Creates a new instance.

public
LengthFieldPrepender(ByteOrder
the ByteOrder of the length field
byteOrder
,
int
the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.
lengthFieldLength
,
int
the compensation value to add to the value of the length field
lengthAdjustment
,
boolean
if true, the length of the prepended length field is added to the value of the prepended length field.
lengthIncludesLengthFieldLength
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
protected void
encode(ChannelHandlerContext ctx, ByteBuf
the message to encode to an other one
msg
,
List<Object>
the List into which the encoded msg should be added needs to do some kind of aggregation
out
)

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other.
Inherited from io.netty.handler.codec.MessageToMessageEncoder:
acceptOutboundMessagewrite

Field Detail

byteOrderback to summary
private final ByteOrder byteOrder
lengthAdjustmentback to summary
private final int lengthAdjustment
lengthFieldLengthback to summary
private final int lengthFieldLength
lengthIncludesLengthFieldLengthback to summary
private final boolean lengthIncludesLengthFieldLength

Constructor Detail

LengthFieldPrependerback to summary
public LengthFieldPrepender(int lengthFieldLength)

Creates a new instance.

Parameters
lengthFieldLength:int

the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.

Exceptions
IllegalArgumentException:
if lengthFieldLength is not 1, 2, 3, 4, or 8
LengthFieldPrependerback to summary
public LengthFieldPrepender(int lengthFieldLength, boolean lengthIncludesLengthFieldLength)

Creates a new instance.

Parameters
lengthFieldLength:int

the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.

lengthIncludesLengthFieldLength:boolean

if true, the length of the prepended length field is added to the value of the prepended length field.

Exceptions
IllegalArgumentException:
if lengthFieldLength is not 1, 2, 3, 4, or 8
LengthFieldPrependerback to summary
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment)

Creates a new instance.

Parameters
lengthFieldLength:int

the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.

lengthAdjustment:int

the compensation value to add to the value of the length field

Exceptions
IllegalArgumentException:
if lengthFieldLength is not 1, 2, 3, 4, or 8
LengthFieldPrependerback to summary
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)

Creates a new instance.

Parameters
lengthFieldLength:int

the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.

lengthAdjustment:int

the compensation value to add to the value of the length field

lengthIncludesLengthFieldLength:boolean

if true, the length of the prepended length field is added to the value of the prepended length field.

Exceptions
IllegalArgumentException:
if lengthFieldLength is not 1, 2, 3, 4, or 8
LengthFieldPrependerback to summary
public LengthFieldPrepender(ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength)

Creates a new instance.

Parameters
byteOrder:ByteOrder

the ByteOrder of the length field

lengthFieldLength:int

the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.

lengthAdjustment:int

the compensation value to add to the value of the length field

lengthIncludesLengthFieldLength:boolean

if true, the length of the prepended length field is added to the value of the prepended length field.

Exceptions
IllegalArgumentException:
if lengthFieldLength is not 1, 2, 3, 4, or 8

Method Detail

encodeback to summary
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Doc from io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to

msg:ByteBuf

the message to encode to an other one

out:List<Object>

the List into which the encoded msg should be added needs to do some kind of aggregation

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs