A response section is simply a count of resource records back to back. Today you parse a run of N records into a list, each one advancing the cursor past its RDATA - the demo that ties the whole chapter together.
Parse a run of N resource records into a list, tracking the cursor across each.
A response does not hold one record - it holds sections, and each section is just a count of resource records laid end to end (the counts come from the header: ANCOUNT, NSCOUNT, ARCOUNT). Parsing a section is therefore a loop: parse a record, advance the cursor by however many bytes it consumed, and repeat for the count. The per-record consumed length you have tracked all chapter is exactly what makes the cursor land on the next record.
The two A records here share a name via compression (both C0 0C pointing at
www.example.com at offset 12), which is the common case in a real answer section
listing several addresses for one host. Parsing them yields a two-element list with
addresses 93.184.216.34 and 93.184.216.35. This is the chapter’s payoff: you
can now read an entire block of answers. Next chapter uses it to parse a full
response and start resolving names for real.
func parseRecords(msg []byte, off, count int) ([]RR, int, error) {var rrs []RRfor k := 0; k < count; k++ {rr, n, err := parseRR(msg, off) // record, byte length, errif err != nil { return nil, off, err }rrs = append(rrs, rr)off += n}return rrs, off, nil}