1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::collections::VecDeque;

use basic_frame::DynamicFrame;

pub(crate) struct PostTriggerBuffer {
    size: usize,
    inner: VecDeque<DynamicFrame>,
}

impl PostTriggerBuffer {
    pub(crate) fn new() -> Self {
        Self {
            size: 0,
            inner: VecDeque::new(),
        }
    }

    fn trim(&mut self) {
        while self.inner.len() > self.size {
            self.inner.pop_front();
        }
    }

    pub(crate) fn set_size(&mut self, size: usize) {
        self.size = size;
        self.trim();
    }

    pub(crate) fn push(&mut self, frame: &DynamicFrame) {
        if self.size > 0 {
            self.inner.push_back(frame.clone());
        }
        self.trim();
    }

    pub(crate) fn get_and_clear(&mut self) -> VecDeque<DynamicFrame> {
        std::mem::take(&mut self.inner)
    }
}