Skip to content

Commit e8609e0

Browse files
committed
Finish to_bytes NSEC RDATA
1 parent d73b3cc commit e8609e0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/message/rdata/nsec_rdata.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,46 @@ impl ToBytes for NsecRdata{
2929
bytes.push(*byte);
3030
}
3131

32+
let bitmap = self.get_type_bit_maps();
33+
34+
let mut encoded_types = Vec::new();
35+
let mut current_window: Option<u8> = None;
36+
let mut current_bitmap = Vec::new();
37+
38+
for rtype in bitmap {
39+
let window = match rtype {
40+
Rtype::UNKNOWN(rr_type) => (rr_type / 256) as u8,
41+
_ => (Rtype::from_rtype_to_int(rtype) / 256) as u8,
42+
};
43+
44+
if let Some(current_window_value) = current_window {
45+
if current_window_value == window {
46+
// We're still in the same window, continue adding to the current bitmap
47+
NsecRdata::add_rtype_to_bitmap(&rtype, &mut current_bitmap);
48+
continue;
49+
} else {
50+
// New window encountered, write the previous window's data
51+
encoded_types.push(current_window_value);
52+
encoded_types.push(current_bitmap.len() as u8);
53+
encoded_types.extend_from_slice(&current_bitmap);
54+
}
55+
}
56+
57+
// Start a new window
58+
current_window = Some(window);
59+
current_bitmap.clear();
60+
NsecRdata::add_rtype_to_bitmap(&rtype, &mut current_bitmap);
61+
}
62+
63+
// Write the final window information
64+
if let Some(current_window_value) = current_window {
65+
encoded_types.push(current_window_value);
66+
encoded_types.push(current_bitmap.len() as u8);
67+
encoded_types.extend_from_slice(&current_bitmap);
68+
}
69+
70+
bytes.extend_from_slice(&encoded_types);
71+
3272
bytes
3373
}
3474
}

0 commit comments

Comments
 (0)