use hickory_resolver::Name;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[allow(clippy::upper_case_acronyms)]
pub struct SRV {
priority: u16,
weight: u16,
port: u16,
target: Name,
}
impl SRV {
pub fn new(priority: u16, weight: u16, port: u16, target: Name) -> SRV {
SRV {
priority,
weight,
port,
target,
}
}
pub fn priority(&self) -> u16 {
self.priority
}
pub fn weight(&self) -> u16 {
self.weight
}
pub fn port(&self) -> u16 {
self.port
}
pub fn target(&self) -> &Name {
&self.target
}
}
#[doc(hidden)]
impl From<hickory_resolver::proto::rr::rdata::SRV> for SRV {
fn from(srv: hickory_resolver::proto::rr::rdata::SRV) -> Self {
SRV {
priority: srv.priority(),
weight: srv.weight(),
port: srv.port(),
target: srv.target().clone(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn srv_new_and_accessors() {
let target = Name::from_utf8("sip.example.com.").unwrap();
let srv = SRV::new(10, 20, 5060, target.clone());
assert_eq!(srv.priority(), 10);
assert_eq!(srv.weight(), 20);
assert_eq!(srv.port(), 5060);
assert_eq!(srv.target(), &target);
}
}