diff --git a/src/dns_parser.rs b/src/dns_parser.rs index 33f0e0c..571ddee 100644 --- a/src/dns_parser.rs +++ b/src/dns_parser.rs @@ -6,7 +6,7 @@ #[cfg(feature = "logging")] use crate::log::debug; -use crate::{Error, Result, ServiceInfo}; +use crate::{service_info::decode_txt, Error, Result, ServiceInfo}; use if_addrs::Interface; use std::{ any::Any, @@ -482,7 +482,7 @@ impl DnsRecordExt for DnsSrv { // marks). Everything up to the first '=' character is the key (Section // 6.4). Everything after the first '=' character to the end of the // string (including subsequent '=' characters, if any) is the value -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct DnsTxt { pub(crate) record: DnsRecord, pub(crate) text: Vec, @@ -525,6 +525,17 @@ impl DnsRecordExt for DnsTxt { } } +impl fmt::Debug for DnsTxt { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let properties = decode_txt(&self.text); + write!( + f, + "DnsTxt {{ record: {:?}, text: {:?} }}", + self.record, properties + ) + } +} + /// A DNS host information record #[derive(Debug, Clone)] struct DnsHostInfo { diff --git a/src/service_info.rs b/src/service_info.rs index 7e9d322..139d99d 100644 --- a/src/service_info.rs +++ b/src/service_info.rs @@ -1,3 +1,5 @@ +//! Define `ServiceInfo` to represent a service and its operations. + #[cfg(feature = "logging")] use crate::log::error; use crate::{dns_parser::split_sub_domain, Error, Result}; @@ -652,7 +654,7 @@ fn encode_txt<'a>(properties: impl Iterator) -> Vec } // Convert from DNS TXT record content to key/value pairs -fn decode_txt(txt: &[u8]) -> Vec { +pub(crate) fn decode_txt(txt: &[u8]) -> Vec { let mut properties = Vec::new(); let mut offset = 0; while offset < txt.len() {