@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;
    }
@Test
    public void testDecodeCompressionRDataPointer() throws Exception {
        DefaultDnsRecordDecoder decoder = new DefaultDnsRecordDecoder();
        byte[] compressionPointer = {
                5, 'n', 'e', 't', 't', 'y', 2, 'i', 'o', 0,
                (byte) 0xC0, 0
        };
        ByteBuf buffer = Unpooled.wrappedBuffer(compressionPointer);
        DefaultDnsRawRecord cnameRecord = null;
        DefaultDnsRawRecord nsRecord = null;
        try {
            cnameRecord = (DefaultDnsRawRecord) decoder.decodeRecord(
                    "netty.github.io", DnsRecordType.CNAME, DnsRecord.CLASS_IN, 60, buffer, 10, 2);
            assertEquals(0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), cnameRecord.content()),
                "The rdata of CNAME-type record should be decompressed in advance");
            assertEquals("netty.io.", DnsCodecUtil.decodeDomainName(cnameRecord.content()));
            nsRecord = (DefaultDnsRawRecord) decoder.decodeRecord(
                    "netty.github.io", DnsRecordType.NS, DnsRecord.CLASS_IN, 60, buffer, 10, 2);
            assertEquals(0, ByteBufUtil.compare(buffer.duplicate().setIndex(0, 10), nsRecord.content()),
                        "The rdata of NS-type record should be decompressed in advance");
            assertEquals("netty.io.", DnsCodecUtil.decodeDomainName(nsRecord.content()));
        } finally {
            buffer.release();
            if (cnameRecord != null) {
                cnameRecord.release();
            }

            if (nsRecord != null) {
                nsRecord.release();
            }
        }
    }