From cad86962efb9940d8e79e4d38798f0eed3738956 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 18 Jun 2009 11:29:29 +0000 Subject: [PATCH] Javadoc --- .../codec/frame/LengthFieldPrepender.java | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/frame/LengthFieldPrepender.java b/src/main/java/org/jboss/netty/handler/codec/frame/LengthFieldPrepender.java index c4f6236579..886cc56979 100644 --- a/src/main/java/org/jboss/netty/handler/codec/frame/LengthFieldPrepender.java +++ b/src/main/java/org/jboss/netty/handler/codec/frame/LengthFieldPrepender.java @@ -24,14 +24,42 @@ package org.jboss.netty.handler.codec.frame; import static org.jboss.netty.buffer.ChannelBuffers.*; +import java.nio.ByteOrder; + import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBufferFactory; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; /** - * TODO Documentation + * An encoder that prepends the length of the message. The length value is + * prepended as a binary form. It is encoded in either big endian or little + * endian depending on the default {@link ByteOrder} of the current + * {@link ChannelBufferFactory}. + *

+ * For example, {@link LengthFieldPrepender}(2) will encode the + * following 12-bytes string: + *

+ * +----------------+
+ * | "HELLO, WORLD" |
+ * +----------------+
+ * 
+ * into the following: + *
+ * +--------+----------------+
+ * + 0x000C | "HELLO, WORLD" |
+ * +--------+----------------+
+ * 
+ * If you turned on the {@code lengthIncludesLengthFieldLength} flag in the + * constructor, the encoded data would look like the following + * (12 (original data) + 2 (prepended data) = 14 (0xE)): + *
+ * +--------+----------------+
+ * + 0x000E | "HELLO, WORLD" |
+ * +--------+----------------+
+ * 
* * @author The Netty Project (netty-dev@lists.jboss.org) * @author Trustin Lee (tlee@redhat.com) @@ -43,10 +71,32 @@ public class LengthFieldPrepender extends OneToOneEncoder { private final int lengthFieldLength; private final boolean lengthIncludesLengthFieldLength; + /** + * Creates a new instance. + * + * @param lengthFieldLength the length of the prepended length field. + * Only 1, 2, 3, 4, and 8 are allowed. + * + * @throws IllegalArgumentException + * if {@code lengthFieldLength} is not 1, 2, 3, 4, or 8 + */ public LengthFieldPrepender(int lengthFieldLength) { this(lengthFieldLength, false); } + /** + * Creates a new instance. + * + * @param lengthFieldLength the length of the prepended length field. + * Only 1, 2, 3, 4, and 8 are allowed. + * @param lengthIncludesLengthFieldLength + * if {@code true}, the length of the prepended + * length field is added to the value of the + * prepended length field. + * + * @throws IllegalArgumentException + * if {@code lengthFieldLength} is not 1, 2, 3, 4, or 8 + */ public LengthFieldPrepender( int lengthFieldLength, boolean lengthIncludesLengthFieldLength) { if (lengthFieldLength != 1 && lengthFieldLength != 2 &&