@ChannelHandler.Sharable public class LengthFieldPrepender extends OneToOneEncoder
ByteOrder
of the current
ChannelBufferFactory
.
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(int lengthFieldLength)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength,
boolean lengthIncludesLengthFieldLength)
Creates a new instance.
|
限定符和类型 | 方法和说明 |
---|---|
protected java.lang.Object |
encode(ChannelHandlerContext ctx,
Channel channel,
java.lang.Object msg)
Transforms the specified message into another message and return the
transformed message.
|
doEncode, handleDownstream
public 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 8protected java.lang.Object encode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg) throws java.lang.Exception
OneToOneEncoder
null
, unlike
you can in OneToOneDecoder.decode(ChannelHandlerContext, Channel, Object)
;
you must return something, at least ChannelBuffers.EMPTY_BUFFER
.encode
在类中 OneToOneEncoder
java.lang.Exception