Skip to content

Commit

Permalink
implement tobytes fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jul 17, 2024
1 parent e39a96a commit d04b775
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/message/rdata/srv_rdata.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,6 +16,36 @@ pub struct SrvRdata {
target: DomainName,
}

impl ToBytes for SrvRdata {
/// Return a `Vec<u8>` of bytes that represents the srv rdata.
fn to_bytes(&self) -> Vec<u8> {
let mut bytes: Vec<u8> = 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.
Expand Down

0 comments on commit d04b775

Please sign in to comment.