DefaultDnsRecordDecoder Class — netty Architecture
Architecture documentation for the DefaultDnsRecordDecoder class in DefaultDnsRecordDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD c16e962c_4ec3_f108_e01f_b69ee7a6f791["DefaultDnsRecordDecoder"] f751bdcb_2d98_d4ef_b22a_c45f688207f9["DefaultDnsRecordDecoder.java"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|defined in| f751bdcb_2d98_d4ef_b22a_c45f688207f9 43569702_3bb4_835b_5563_12b79857cce1["DefaultDnsRecordDecoder()"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|method| 43569702_3bb4_835b_5563_12b79857cce1 9fc2493e_1108_83ed_2f8c_2aa62730a57a["DnsQuestion()"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|method| 9fc2493e_1108_83ed_2f8c_2aa62730a57a 91e14caa_b636_5c54_b50c_5c8b9e0226b9["T()"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|method| 91e14caa_b636_5c54_b50c_5c8b9e0226b9 6c10a76a_10a1_2baa_c2d7_930c4b884c79["DnsRecord()"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|method| 6c10a76a_10a1_2baa_c2d7_930c4b884c79 5a160275_ea0a_7ead_1393_b9e101668b95["String()"] c16e962c_4ec3_f108_e01f_b69ee7a6f791 -->|method| 5a160275_ea0a_7ead_1393_b9e101668b95
Relationship Graph
Source Code
codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoder.java lines 27–155
public class DefaultDnsRecordDecoder implements DnsRecordDecoder {
static final String ROOT = ".";
/**
* Creates a new instance.
*/
protected DefaultDnsRecordDecoder() { }
@Override
public final DnsQuestion decodeQuestion(ByteBuf in) throws Exception {
String name = decodeName(in);
DnsRecordType type = DnsRecordType.valueOf(in.readUnsignedShort());
int qClass = in.readUnsignedShort();
return new DefaultDnsQuestion(name, type, qClass);
}
@Override
public final <T extends DnsRecord> T decodeRecord(ByteBuf in) throws Exception {
final int startOffset = in.readerIndex();
final String name = decodeName(in);
final int endOffset = in.writerIndex();
if (endOffset - in.readerIndex() < 10) {
// Not enough data
in.readerIndex(startOffset);
return null;
}
final DnsRecordType type = DnsRecordType.valueOf(in.readUnsignedShort());
final int aClass = in.readUnsignedShort();
final long ttl = in.readUnsignedInt();
final int length = in.readUnsignedShort();
final int offset = in.readerIndex();
if (endOffset - offset < length) {
// Not enough data
in.readerIndex(startOffset);
return null;
}
@SuppressWarnings("unchecked")
T record = (T) decodeRecord(name, type, aClass, ttl, in, offset, length);
in.readerIndex(offset + length);
return record;
}
/**
* Decodes a record from the information decoded so far by {@link #decodeRecord(ByteBuf)}.
*
* @param name the domain name of the record
* @param type the type of the record
* @param dnsClass the class of the record
* @param timeToLive the TTL of the record
* @param in the {@link ByteBuf} that contains the RDATA
* @param offset the start offset of the RDATA in {@code in}
* @param length the length of the RDATA
*
* @return a {@link DnsRawRecord}. Override this method to decode RDATA and return other record implementation.
*/
protected DnsRecord decodeRecord(
String name, DnsRecordType type, int dnsClass, long timeToLive,
ByteBuf in, int offset, int length) throws Exception {
// DNS message compression means that domain names may contain "pointers" to other positions in the packet
// to build a full message. This means the indexes are meaningful and we need the ability to reference the
// indexes un-obstructed, and thus we cannot use a slice here.
// See https://www.ietf.org/rfc/rfc1035 [4.1.4. Message compression]
if (type == DnsRecordType.PTR) {
return new DefaultDnsPtrRecord(
name, dnsClass, timeToLive, decodeName0(in.duplicate().setIndex(offset, offset + length)));
}
if (type == DnsRecordType.CNAME || type == DnsRecordType.NS) {
return new DefaultDnsRawRecord(name, type, dnsClass, timeToLive,
DnsCodecUtil.decompressDomainName(
in.duplicate().setIndex(offset, offset + length)));
}
if (type == DnsRecordType.MX) {
// MX RDATA: 16-bit preference + exchange (domain name, possibly compressed)
if (length < 3) {
throw new CorruptedFrameException("MX record RDATA is too short: " + length);
Source
Frequently Asked Questions
What is the DefaultDnsRecordDecoder class?
DefaultDnsRecordDecoder is a class in the netty codebase, defined in codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoder.java.
Where is DefaultDnsRecordDecoder defined?
DefaultDnsRecordDecoder is defined in codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordDecoder.java at line 27.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free