Decodes a domain name from a message, following compression pointers.
A length byte with its top two bits set (0xC0) is a pointer to an earlier offset; this
follows the chain with a loop guard (a pointer must be seen at most once). The returned next
is the offset immediately after the name in the linear stream - after the first pointer, if
one is present - which is what a caller uses to continue parsing.
Parameters
msg: Uint8Array
The full message buffer (needed to resolve pointers).
offset: number
Where the name begins.
Returns {name:string;next:number}
The decoded name and the offset just past it in the linear stream.
Throws
If the name runs past the buffer, uses a reserved label form, or a
compression pointer loops.
Since
1.0.4
Example
import { decodeName } from'edgeport/dns';
const { name, next } = decodeName(messageBytes, 12);
Decodes a domain name from a message, following compression pointers.
A length byte with its top two bits set (
0xC0) is a pointer to an earlier offset; this follows the chain with a loop guard (a pointer must be seen at most once). The returnednextis the offset immediately after the name in the linear stream - after the first pointer, if one is present - which is what a caller uses to continue parsing.