Domain names on the wire are not dotted strings - they are sequences of length-prefixed labels. Today you encode a single label, the building block of every name, by putting its byte count in front of its characters.
Encode one label as its length byte followed by its ASCII characters.
A DNS name like www.example.com is never sent as text with dots. Instead it is a
run of labels, and each label is a single length byte (how many characters
follow) then those characters as raw ASCII. The dots are implied by where one
label ends and the next begins. So example becomes the byte 7 followed by the
seven bytes of example.
This length-prefix framing is what lets a parser walk a name without needing a delimiter: read one byte, then read that many characters, repeat. A single label’s length must fit in six bits (at most 63), because the top two bits of a length byte are reserved for something you will meet in chapter three. Today just nail the one-label case; stringing labels together into a full name is next.
func encodeLabel(s string) []byte {out := []byte{byte(len(s))} // the length prefixreturn append(out, s...) // then the raw characters}// "example" -> 07 'e' 'x' 'a' 'm' 'p' 'l' 'e'