dns_encode

Function dns_encode 

Source
pub fn dns_encode(domain: &str) -> Result<Vec<u8>, String>
Expand description

Encodes a domain name into its binary representation according to the DNS wire format. Each label (i.e., substring separated by dots) in the domain is prefixed with its length, and the encoded domain name is terminated with a root label (length 0).

§Arguments

  • domain - A domain name as a string (e.g., “tanrikulu.eth”).

§Returns

  • A Result containing the encoded domain name as a Vec<u8> on success, or an error message as a String if any of the labels in the domain name are too long (exceeding 63 characters).

§Example

use ethers_ccip_read::utils::{dns_encode};

let encoded = dns_encode("tanrikulu.eth").unwrap();
assert_eq!(encoded, vec![9, b't', b'a', b'n', b'r', b'i', b'k', b'u', b'l', b'u', 3, b'e', b't', b'h', 0]);