decode() — netty Function Reference
Architecture documentation for the decode() function in XmlFrameDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 16b71bcb_9bc6_dcdf_9d02_291227b77db6["decode()"] 7d6b87e5_eb7b_72e0_1afd_174c09a039b0["XmlFrameDecoder"] 16b71bcb_9bc6_dcdf_9d02_291227b77db6 -->|defined in| 7d6b87e5_eb7b_72e0_1afd_174c09a039b0 23b37d5f_23cf_0f21_3b33_fd790dcc0476["fail()"] 16b71bcb_9bc6_dcdf_9d02_291227b77db6 -->|calls| 23b37d5f_23cf_0f21_3b33_fd790dcc0476 5e926dca_a4e1_c95b_d634_6ca4f87b600b["isValidStartCharForXmlElement()"] 16b71bcb_9bc6_dcdf_9d02_291227b77db6 -->|calls| 5e926dca_a4e1_c95b_d634_6ca4f87b600b 3a7fee41_cc4a_eb14_8d1a_edf3de107e18["isCommentBlockStart()"] 16b71bcb_9bc6_dcdf_9d02_291227b77db6 -->|calls| 3a7fee41_cc4a_eb14_8d1a_edf3de107e18 56cf43c0_f19c_4ce5_a232_f932718a5dd2["isCDATABlockStart()"] 16b71bcb_9bc6_dcdf_9d02_291227b77db6 -->|calls| 56cf43c0_f19c_4ce5_a232_f932718a5dd2 style 16b71bcb_9bc6_dcdf_9d02_291227b77db6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java lines 86–193
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
boolean openingBracketFound = false;
boolean atLeastOneXmlElementFound = false;
boolean inCDATASection = false;
long openBracketsCount = 0;
int length = 0;
int leadingWhiteSpaceCount = 0;
final int bufferLength = in.writerIndex();
if (bufferLength > maxFrameLength) {
// bufferLength exceeded maxFrameLength; dropping frame
in.skipBytes(in.readableBytes());
fail(bufferLength);
return;
}
for (int i = in.readerIndex(); i < bufferLength; i++) {
final byte readByte = in.getByte(i);
if (!openingBracketFound && Character.isWhitespace(readByte)) {
// xml has not started and whitespace char found
leadingWhiteSpaceCount++;
} else if (!openingBracketFound && readByte != '<') {
// garbage found before xml start
fail(ctx);
in.skipBytes(in.readableBytes());
return;
} else if (!inCDATASection && readByte == '<') {
openingBracketFound = true;
if (i < bufferLength - 1) {
final byte peekAheadByte = in.getByte(i + 1);
if (peekAheadByte == '/') {
// found </, we must check if it is enclosed
int peekFurtherAheadIndex = i + 2;
while (peekFurtherAheadIndex <= bufferLength - 1) {
//if we have </ and enclosing > we can decrement openBracketsCount
if (in.getByte(peekFurtherAheadIndex) == '>') {
openBracketsCount--;
break;
}
peekFurtherAheadIndex++;
}
} else if (isValidStartCharForXmlElement(peekAheadByte)) {
atLeastOneXmlElementFound = true;
// char after < is a valid xml element start char,
// incrementing openBracketsCount
openBracketsCount++;
} else if (peekAheadByte == '!') {
if (isCommentBlockStart(in, i)) {
// <!-- comment --> start found
openBracketsCount++;
} else if (isCDATABlockStart(in, i)) {
// <![CDATA[ start found
openBracketsCount++;
inCDATASection = true;
}
} else if (peekAheadByte == '?') {
// <?xml ?> start found
openBracketsCount++;
}
}
} else if (!inCDATASection && readByte == '/') {
if (i < bufferLength - 1 && in.getByte(i + 1) == '>') {
// found />, decrementing openBracketsCount
openBracketsCount--;
}
} else if (readByte == '>') {
length = i + 1;
if (i - 1 > -1) {
final byte peekBehindByte = in.getByte(i - 1);
if (!inCDATASection) {
if (peekBehindByte == '?') {
// an <?xml ?> tag was closed
openBracketsCount--;
} else if (peekBehindByte == '-' && i - 2 > -1 && in.getByte(i - 2) == '-') {
// a <!-- comment --> was closed
openBracketsCount--;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java.
Where is decode() defined?
decode() is defined in codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java at line 86.
What does decode() call?
decode() calls 4 function(s): fail, isCDATABlockStart, isCommentBlockStart, isValidStartCharForXmlElement.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free