@@ -29,6 +29,46 @@ impl ToBytes for NsecRdata{
29
29
bytes. push ( * byte) ;
30
30
}
31
31
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
+
32
72
bytes
33
73
}
34
74
}
0 commit comments