DnsResponseDecoder Class — netty Architecture
Architecture documentation for the DnsResponseDecoder class in DnsResponseDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b4477e00_485f_d1b0_e814_416dcbb42b0f["DnsResponseDecoder"] 80c1c405_d86e_777c_c069_c49466342687["DnsResponseDecoder.java"] b4477e00_485f_d1b0_e814_416dcbb42b0f -->|defined in| 80c1c405_d86e_777c_c069_c49466342687 c7e488f8_ca98_8748_a8f1_e0a2379fbc30["DnsResponseDecoder()"] b4477e00_485f_d1b0_e814_416dcbb42b0f -->|method| c7e488f8_ca98_8748_a8f1_e0a2379fbc30 200ea77b_0329_96bf_cdf6_5b84187a1993["DnsResponse()"] b4477e00_485f_d1b0_e814_416dcbb42b0f -->|method| 200ea77b_0329_96bf_cdf6_5b84187a1993 8627d2c9_0e00_24db_49db_4ff1527098fa["decodeQuestions()"] b4477e00_485f_d1b0_e814_416dcbb42b0f -->|method| 8627d2c9_0e00_24db_49db_4ff1527098fa bdfca86f_0ca1_14e1_12e8_42bfd4ed6746["decodeRecords()"] b4477e00_485f_d1b0_e814_416dcbb42b0f -->|method| bdfca86f_0ca1_14e1_12e8_42bfd4ed6746
Relationship Graph
Source Code
codec-dns/src/main/java/io/netty/handler/codec/dns/DnsResponseDecoder.java lines 25–105
abstract class DnsResponseDecoder<A extends SocketAddress> {
private final DnsRecordDecoder recordDecoder;
/**
* Creates a new decoder with the specified {@code recordDecoder}.
*/
DnsResponseDecoder(DnsRecordDecoder recordDecoder) {
this.recordDecoder = checkNotNull(recordDecoder, "recordDecoder");
}
final DnsResponse decode(A sender, A recipient, ByteBuf buffer) throws Exception {
final int id = buffer.readUnsignedShort();
final int flags = buffer.readUnsignedShort();
if (flags >> 15 == 0) {
throw new CorruptedFrameException("not a response");
}
final DnsResponse response = newResponse(
sender,
recipient,
id,
DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf)));
response.setRecursionDesired((flags >> 8 & 1) == 1);
response.setAuthoritativeAnswer((flags >> 10 & 1) == 1);
response.setTruncated((flags >> 9 & 1) == 1);
response.setRecursionAvailable((flags >> 7 & 1) == 1);
response.setZ(flags >> 4 & 0x7);
boolean success = false;
try {
final int questionCount = buffer.readUnsignedShort();
final int answerCount = buffer.readUnsignedShort();
final int authorityRecordCount = buffer.readUnsignedShort();
final int additionalRecordCount = buffer.readUnsignedShort();
decodeQuestions(response, buffer, questionCount);
if (!decodeRecords(response, DnsSection.ANSWER, buffer, answerCount)) {
success = true;
return response;
}
if (!decodeRecords(response, DnsSection.AUTHORITY, buffer, authorityRecordCount)) {
success = true;
return response;
}
decodeRecords(response, DnsSection.ADDITIONAL, buffer, additionalRecordCount);
success = true;
return response;
} finally {
if (!success) {
response.release();
}
}
}
protected abstract DnsResponse newResponse(A sender, A recipient, int id,
DnsOpCode opCode, DnsResponseCode responseCode) throws Exception;
private void decodeQuestions(DnsResponse response, ByteBuf buf, int questionCount) throws Exception {
for (int i = questionCount; i > 0; i --) {
response.addRecord(DnsSection.QUESTION, recordDecoder.decodeQuestion(buf));
}
}
private boolean decodeRecords(
DnsResponse response, DnsSection section, ByteBuf buf, int count) throws Exception {
for (int i = count; i > 0; i --) {
final DnsRecord r = recordDecoder.decodeRecord(buf);
if (r == null) {
// Truncated response
return false;
}
response.addRecord(section, r);
}
return true;
}
}
Source
Frequently Asked Questions
What is the DnsResponseDecoder class?
DnsResponseDecoder is a class in the netty codebase, defined in codec-dns/src/main/java/io/netty/handler/codec/dns/DnsResponseDecoder.java.
Where is DnsResponseDecoder defined?
DnsResponseDecoder is defined in codec-dns/src/main/java/io/netty/handler/codec/dns/DnsResponseDecoder.java at line 25.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free