Skip to main content

orbit_rs/ring/cursor/
poll.rs

1use crate::ring::Frame;
2
3/// Counters skipped while walking a ring.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5pub struct RingLoss {
6    /// Counters older than the current ring window.
7    pub overwritten: u64,
8    /// Counters inside the readable window whose slot was empty, torn,
9    /// wrapped, or carried an unexpected frame id.
10    pub unavailable: u64,
11}
12
13impl RingLoss {
14    pub const fn total(self) -> u64 {
15        self.overwritten.saturating_add(self.unavailable)
16    }
17
18    pub const fn is_empty(self) -> bool {
19        self.overwritten == 0 && self.unavailable == 0
20    }
21}
22
23/// Result of walking a cursor to a ring head.
24#[derive(Clone, Debug, Default, PartialEq, Eq)]
25pub struct RingPoll {
26    pub frames: Vec<Frame>,
27    pub loss: RingLoss,
28    pub from_counter: u64,
29    pub to_counter: u64,
30}
31
32impl RingPoll {
33    pub fn is_empty(&self) -> bool {
34        self.frames.is_empty() && self.loss.is_empty()
35    }
36}