The root of the DNS tree has an empty name, and it encodes to a single zero byte. Today you handle that edge so an empty or dot-only name does not produce a stray empty label.
Encode the empty root name as exactly one zero byte.
The very top of the domain namespace is the root, written as . or nothing at
all, and its on-the-wire form is a name with no labels - just the zero terminator,
a single 00 byte. Your lesson 7 encoder would trip on this: splitting "" on
dots yields one empty string, which would encode as a bogus zero-length label and
then another zero terminator. Both look like 00, so the result would be two
zero bytes instead of one.
The fix is a small guard: strip a trailing dot, and if nothing is left, emit just
the single terminator. This matters because the root name appears for real - it is
the name you query when you ask a root server for a top-level domain’s servers, and
it is the SOA and NS owner at a zone apex. Handle it now and every later name,
from a to a long fully-qualified one, encodes cleanly.
func encodeName(name string) []byte {name = strings.TrimSuffix(name, ".")if name == "" {return []byte{0x00} // the root is just the terminator}// ...otherwise encode each label then append 0x00}