diff --git a/src/message/rdata/srv_rdata.rs b/src/message/rdata/srv_rdata.rs index 41a00c40..c2e76ec1 100644 --- a/src/message/rdata/srv_rdata.rs +++ b/src/message/rdata/srv_rdata.rs @@ -1,4 +1,5 @@ use crate::domain_name::DomainName; +use crate::message::resource_record::{FromBytes, ToBytes}; /// RFC 2782: https://datatracker.ietf.org/doc/html/rfc2782 @@ -15,6 +16,36 @@ pub struct SrvRdata { target: DomainName, } +impl ToBytes for SrvRdata { + /// Return a `Vec` of bytes that represents the srv rdata. + fn to_bytes(&self) -> Vec { + let mut bytes: Vec = Vec::new(); + let priority_bytes = self.get_priority().to_be_bytes(); + let weight_bytes = self.get_weight().to_be_bytes(); + let port_bytes = self.get_port().to_be_bytes(); + let target_bytes = self.get_target().to_bytes(); + + for byte in priority_bytes.as_slice() { + bytes.push(*byte); + } + + for byte in weight_bytes.as_slice() { + bytes.push(*byte); + } + + for byte in port_bytes.as_slice() { + bytes.push(*byte); + } + + for byte in target_bytes.as_slice() { + bytes.push(*byte); + } + + bytes + + } +} + impl SrvRdata { /// Creates a new `SrvRdata` with default values.