pub struct DuplicateWindow { /* private fields */ }Expand description
Bounded exact-byte duplicate window.
Implementations§
Source§impl DuplicateWindow
impl DuplicateWindow
Sourcepub const fn new(capacity: usize) -> Self
pub const fn new(capacity: usize) -> Self
Creates a duplicate window retaining at most capacity packet byte
sequences. A zero-capacity window never retains packets.
Examples found in repository?
examples/service_toolkit.rs (line 12)
10fn main() -> Result<(), libaprs_engine::ParseError> {
11 let mut engine = Engine::default();
12 let mut duplicates = DuplicateWindow::new(128);
13 let mut rate = PacketRateBudget::new(100);
14 let blocked = SemanticBlocklist::new(&[SemanticFamily::Unsupported, SemanticFamily::Malformed]);
15
16 for packet_bytes in [b"N0CALL>APRS:>service".as_slice()] {
17 if rate.try_consume() == RateLimitDecision::Limited {
18 continue;
19 }
20 if duplicates.observe(packet_bytes) == DuplicateDecision::Duplicate {
21 continue;
22 }
23
24 let packet = parse_packet(packet_bytes)?;
25 if blocked.rejects(&packet.aprs_data()) {
26 continue;
27 }
28
29 let _event = engine.process_event(packet.raw().as_bytes());
30 }
31
32 Ok(())
33}Sourcepub fn observe(&mut self, packet: &[u8]) -> DuplicateDecision
pub fn observe(&mut self, packet: &[u8]) -> DuplicateDecision
Observes packet bytes and reports whether the exact bytes were recently retained.
Examples found in repository?
examples/service_toolkit.rs (line 20)
10fn main() -> Result<(), libaprs_engine::ParseError> {
11 let mut engine = Engine::default();
12 let mut duplicates = DuplicateWindow::new(128);
13 let mut rate = PacketRateBudget::new(100);
14 let blocked = SemanticBlocklist::new(&[SemanticFamily::Unsupported, SemanticFamily::Malformed]);
15
16 for packet_bytes in [b"N0CALL>APRS:>service".as_slice()] {
17 if rate.try_consume() == RateLimitDecision::Limited {
18 continue;
19 }
20 if duplicates.observe(packet_bytes) == DuplicateDecision::Duplicate {
21 continue;
22 }
23
24 let packet = parse_packet(packet_bytes)?;
25 if blocked.rejects(&packet.aprs_data()) {
26 continue;
27 }
28
29 let _event = engine.process_event(packet.raw().as_bytes());
30 }
31
32 Ok(())
33}Sourcepub fn retained_len(&self) -> usize
pub fn retained_len(&self) -> usize
Returns the number of packet byte sequences currently retained.
Trait Implementations§
Source§impl Clone for DuplicateWindow
impl Clone for DuplicateWindow
Source§fn clone(&self) -> DuplicateWindow
fn clone(&self) -> DuplicateWindow
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DuplicateWindow
impl Debug for DuplicateWindow
Source§impl PartialEq for DuplicateWindow
impl PartialEq for DuplicateWindow
Source§fn eq(&self, other: &DuplicateWindow) -> bool
fn eq(&self, other: &DuplicateWindow) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for DuplicateWindow
impl StructuralPartialEq for DuplicateWindow
Auto Trait Implementations§
impl Freeze for DuplicateWindow
impl RefUnwindSafe for DuplicateWindow
impl Send for DuplicateWindow
impl Sync for DuplicateWindow
impl Unpin for DuplicateWindow
impl UnsafeUnpin for DuplicateWindow
impl UnwindSafe for DuplicateWindow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more