LineBasedFrameDecoder Class — netty Architecture
Architecture documentation for the LineBasedFrameDecoder class in LineBasedFrameDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 08c792ec_5667_895a_55fc_02629ffcaf54["LineBasedFrameDecoder"] 11311d1a_bfaa_4b10_a5b3_badc0ac7fe7f["LineBasedFrameDecoder.java"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|defined in| 11311d1a_bfaa_4b10_a5b3_badc0ac7fe7f 794e2ab5_0106_3bd5_21b7_5ccdaf63d1a1["LineBasedFrameDecoder()"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|method| 794e2ab5_0106_3bd5_21b7_5ccdaf63d1a1 a8a1df55_7bfa_e31b_ee41_95a3223caeac["decode()"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|method| a8a1df55_7bfa_e31b_ee41_95a3223caeac 97847d6b_9dc8_0746_16ea_4c2d510bc195["Object()"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|method| 97847d6b_9dc8_0746_16ea_4c2d510bc195 a8b7f592_6df6_9f07_0fde_8620faef55ba["fail()"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|method| a8b7f592_6df6_9f07_0fde_8620faef55ba 72b78205_eb7d_1a65_de66_6f6782ec723c["findEndOfLine()"] 08c792ec_5667_895a_55fc_02629ffcaf54 -->|method| 72b78205_eb7d_1a65_de66_6f6782ec723c
Relationship Graph
Source Code
codec-base/src/main/java/io/netty/handler/codec/LineBasedFrameDecoder.java lines 42–187
public class LineBasedFrameDecoder extends ByteToMessageDecoder {
/** Maximum length of a frame we're willing to decode. */
private final int maxLength;
/** Whether or not to throw an exception as soon as we exceed maxLength. */
private final boolean failFast;
private final boolean stripDelimiter;
/** True if we're discarding input because we're already over maxLength. */
private boolean discarding;
private int discardedBytes;
/** Last scan position. */
private int offset;
/**
* Creates a new decoder.
* @param maxLength the maximum length of the decoded frame.
* A {@link TooLongFrameException} is thrown if
* the length of the frame exceeds this value.
*/
public LineBasedFrameDecoder(final int maxLength) {
this(maxLength, true, false);
}
/**
* Creates a new decoder.
* @param maxLength the maximum length of the decoded frame.
* A {@link TooLongFrameException} is thrown if
* the length of the frame exceeds this value.
* @param stripDelimiter whether the decoded frame should strip out the
* delimiter or not
* @param failFast If <tt>true</tt>, a {@link TooLongFrameException} is
* thrown as soon as the decoder notices the length of the
* frame will exceed <tt>maxFrameLength</tt> regardless of
* whether the entire frame has been read.
* If <tt>false</tt>, a {@link TooLongFrameException} is
* thrown after the entire frame that exceeds
* <tt>maxFrameLength</tt> has been read.
*/
public LineBasedFrameDecoder(final int maxLength, final boolean stripDelimiter, final boolean failFast) {
this.maxLength = maxLength;
this.failFast = failFast;
this.stripDelimiter = stripDelimiter;
}
@Override
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
Object decoded = decode(ctx, in);
if (decoded != null) {
out.add(decoded);
}
}
/**
* Create a frame out of the {@link ByteBuf} and return it.
*
* @param ctx the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
* @param buffer the {@link ByteBuf} from which to read data
* @return frame the {@link ByteBuf} which represent the frame or {@code null} if no frame could
* be created.
*/
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
final int eol = findEndOfLine(buffer);
if (!discarding) {
if (eol >= 0) {
final ByteBuf frame;
final int length = eol - buffer.readerIndex();
final int delimLength = buffer.getByte(eol) == '\r'? 2 : 1;
if (length > maxLength) {
buffer.readerIndex(eol + delimLength);
fail(ctx, length);
return null;
}
if (stripDelimiter) {
frame = buffer.readRetainedSlice(length);
buffer.skipBytes(delimLength);
} else {
frame = buffer.readRetainedSlice(length + delimLength);
Source
Frequently Asked Questions
What is the LineBasedFrameDecoder class?
LineBasedFrameDecoder is a class in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/LineBasedFrameDecoder.java.
Where is LineBasedFrameDecoder defined?
LineBasedFrameDecoder is defined in codec-base/src/main/java/io/netty/handler/codec/LineBasedFrameDecoder.java at line 42.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free