@@ -8,6 +8,8 @@ use anyhow::Result;
88use bytes:: { Buf , BufMut } ;
99use std:: any:: Any ;
1010use std:: fmt;
11+ use std:: future:: Future ;
12+ use std:: pin:: Pin ;
1113
1214/// PacketBitmap shouldn't be used like a normal integral,
1315/// so it's type is masked here. Access it with PacketList().
@@ -23,6 +25,9 @@ pub struct NackPair {
2325 pub lost_packets : PacketBitmap ,
2426}
2527
28+ pub type RangeFn =
29+ Box < dyn ( Fn ( u16 ) -> Pin < Box < dyn Future < Output = bool > + Send + ' static > > ) + Send + Sync > ;
30+
2631impl NackPair {
2732 /// PacketList returns a list of Nack'd packets that's referenced by a NackPair
2833 pub fn packet_list ( & self ) -> Vec < u16 > {
@@ -40,6 +45,25 @@ impl NackPair {
4045 }
4146 out
4247 }
48+
49+ pub async fn range ( & self , f : RangeFn ) {
50+ if !f ( self . packet_id ) . await {
51+ return ;
52+ }
53+
54+ let mut b = self . lost_packets ;
55+ let mut i = 0u16 ;
56+ while b != 0 {
57+ if ( b & ( 1 << i) ) != 0 {
58+ b &= u16:: MAX ^ ( 1 << i) ;
59+ let ( packet_id, _) = self . packet_id . overflowing_add ( i + 1 ) ;
60+ if !f ( packet_id) . await {
61+ return ;
62+ }
63+ }
64+ i += 1 ;
65+ }
66+ }
4367}
4468
4569const TLN_LENGTH : usize = 2 ;
@@ -189,7 +213,7 @@ impl Unmarshal for TransportLayerNack {
189213 }
190214}
191215
192- fn nack_pairs_from_sequence_numbers ( seq_nos : & [ u16 ] ) -> Vec < NackPair > {
216+ pub fn nack_pairs_from_sequence_numbers ( seq_nos : & [ u16 ] ) -> Vec < NackPair > {
193217 if seq_nos. is_empty ( ) {
194218 return vec ! [ ] ;
195219 }
0 commit comments