@ChannelHandler.Sharable public class LengthFieldPrepender extends MessageToByteEncoder<io.netty.buffer.ByteBuf>
ByteOrder of the current
ByteBufFactory.
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" | +--------+----------------+
| Constructor and Description |
|---|
LengthFieldPrepender(int lengthFieldLength)
Creates a new instance.
|
LengthFieldPrepender(int lengthFieldLength,
boolean lengthIncludesLengthFieldLength)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
io.netty.buffer.ByteBuf out) |
flush, isEncodablenewOutboundBufferafterAdd, afterRemove, beforeAdd, beforeRemove, bind, close, connect, deregister, disconnect, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic LengthFieldPrepender(int lengthFieldLength)
lengthFieldLength - the length of the prepended length field.
Only 1, 2, 3, 4, and 8 are allowed.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.IllegalArgumentException - if lengthFieldLength is not 1, 2, 3, 4, or 8public void encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
io.netty.buffer.ByteBuf out)
throws Exception
encode in class MessageToByteEncoder<io.netty.buffer.ByteBuf>ExceptionCopyright © 2008-2012 The Netty Project. All Rights Reserved.