Class LengthFieldPrepender
java.lang.Object
- All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
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" | +--------+----------------+
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
Constructor Summary
ConstructorsConstructorDescriptionLengthFieldPrepender(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.LengthFieldPrepender(ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidencode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) Encode from one message to an other.Methods inherited from class MessageToMessageEncoder
acceptOutboundMessage, writeModifier and TypeMethodDescriptionbooleanReturnstrueif the given message should be handled.voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, readModifier and TypeMethodDescriptionvoidbind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.bind(SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidconnect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidderegister(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.deregister(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voiddisconnect(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.disconnect(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.flush()to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.read()to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableModifier and TypeMethodDescriptionprotected voidvoidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) Deprecated.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.booleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
Constructor Details
-
LengthFieldPrepender
public LengthFieldPrepender(int lengthFieldLength) Creates a new instance.- Parameters:
lengthFieldLength- the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.- Throws:
IllegalArgumentException- iflengthFieldLengthis not 1, 2, 3, 4, or 8
-
LengthFieldPrepender
public LengthFieldPrepender(int lengthFieldLength, boolean lengthIncludesLengthFieldLength) Creates a new instance.- Parameters:
lengthFieldLength- the length of the prepended length field. Only 1, 2, 3, 4, and 8 are allowed.lengthIncludesLengthFieldLength- iftrue, the length of the prepended length field is added to the value of the prepended length field.- Throws:
IllegalArgumentException- iflengthFieldLengthis not 1, 2, 3, 4, or 8
-
LengthFieldPrepender
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment) Creates a new instance.- Parameters:
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 field- Throws:
IllegalArgumentException- iflengthFieldLengthis not 1, 2, 3, 4, or 8
-
LengthFieldPrepender
public LengthFieldPrepender(int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength) Creates a new instance.- Parameters:
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- iftrue, the length of the prepended length field is added to the value of the prepended length field.- Throws:
IllegalArgumentException- iflengthFieldLengthis not 1, 2, 3, 4, or 8
-
LengthFieldPrepender
public LengthFieldPrepender(ByteOrder byteOrder, int lengthFieldLength, int lengthAdjustment, boolean lengthIncludesLengthFieldLength) Creates a new instance.- Parameters:
byteOrder- theByteOrderof 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- iftrue, the length of the prepended length field is added to the value of the prepended length field.- Throws:
IllegalArgumentException- iflengthFieldLengthis not 1, 2, 3, 4, or 8
-
-
Method Details
-
encode
Description copied from class:MessageToMessageEncoderEncode from one message to an other. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToMessageEncoder<ByteBuf>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageEncoderbelongs tomsg- the message to encode to an other oneout- theListinto which the encoded msg should be added needs to do some kind of aggregation- Throws:
Exception- is thrown if an error occurs
-
ChannelInboundHandler