Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit a435f68

Browse files
author
Rain Liu
committed
make nack_pairs_from_sequence_numbers public and add range fn
1 parent f546ddf commit a435f68

File tree

1 file changed

+25
-1
lines changed
  • src/transport_feedbacks/transport_layer_nack

1 file changed

+25
-1
lines changed

src/transport_feedbacks/transport_layer_nack/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use anyhow::Result;
88
use bytes::{Buf, BufMut};
99
use std::any::Any;
1010
use 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+
2631
impl 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

4569
const 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

Comments
 (0)