From c4baccf7171a137d048027db718fb115e0c12651 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Wed, 17 Jul 2024 17:41:09 -0400 Subject: [PATCH] Implement to_bytes function for SrvRdata --- src/message/rdata/srv_rdata.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/message/rdata/srv_rdata.rs b/src/message/rdata/srv_rdata.rs index 2461c000..3a2e7fc2 100644 --- a/src/message/rdata/srv_rdata.rs +++ b/src/message/rdata/srv_rdata.rs @@ -177,4 +177,34 @@ mod srv_rdata_tests { assert_eq!(srv_rdata.get_port(), 3); assert_eq!(srv_rdata.get_target(), DomainName::new_from_str("www.example.com")); } + + #[test] + fn to_bytes() { + let srv_rdata = SrvRdata::new_with_values(1, 2, 3, DomainName::new_from_str("www.example.com")); + let bytes = srv_rdata.to_bytes(); + let expected_bytes = vec![0, 1, + 0, 2, + 0, 3, + 3, 119, 119, 119, + 7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, + 0]; + assert_eq!(bytes, expected_bytes); + } + + #[test] + fn from_bytes() { + let bytes = vec![0, 1, + 0, 2, + 0, 3, + 3, 119, 119, 119, + 7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, + 0]; + + let srv_rdata = SrvRdata::from_bytes(&bytes, &bytes).unwrap(); + + assert_eq!(srv_rdata.get_priority(), 1); + assert_eq!(srv_rdata.get_weight(), 2); + assert_eq!(srv_rdata.get_port(), 3); + assert_eq!(srv_rdata.get_target(), DomainName::new_from_str("www.example.com")); + } } \ No newline at end of file