pub struct RingBufferCapture { /* private fields */ }Expand description
In-memory packet capture with optional ring-buffer eviction.
Prefer crate::BusCapture for most use cases — it includes
statistics counters and supports stats-only, bounded, and unbounded
modes. Use RingBufferCapture only when you need a standalone
ring buffer without statistics tracking.
§Example
use oms_modbus::monitor::RingBufferCapture;
let capture = RingBufferCapture::new(10_000); // bounded, 10k recordsImplementations§
Source§impl RingBufferCapture
impl RingBufferCapture
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a bounded ring buffer with the given capacity. When full, oldest records are evicted.
capacity is clamped to a minimum of 1. Passing 0 is equivalent to
passing 1 — a single-record buffer.
Sourcepub fn unbounded() -> Self
pub fn unbounded() -> Self
Create an unbounded capture that never drops records. Use with caution — memory grows indefinitely.
Sourcepub fn dropped(&self) -> u64
pub fn dropped(&self) -> u64
Number of records dropped due to buffer overflow (bounded mode only).
Sourcepub fn drain(&self) -> Vec<PacketRecord>
pub fn drain(&self) -> Vec<PacketRecord>
Drain all records in chronological order. Clears the buffer.
Sourcepub fn snapshot(&self) -> Vec<PacketRecord>
pub fn snapshot(&self) -> Vec<PacketRecord>
Take a snapshot without clearing. Records are in chronological order.
Clones all records under the lock. For large buffers in hot paths,
prefer Self::drain which swaps the buffer and releases the lock immediately.
Sourcepub fn set_unbounded(&self)
pub fn set_unbounded(&self)
Switch to unbounded mode (existing records preserved).
Sourcepub fn set_bounded(&self)
pub fn set_bounded(&self)
Switch to bounded mode, stopping unbounded growth.
Capacity is fixed at construction time; this only prevents the ring
buffer from growing without bound. Use RingBufferCapture::new
to create a capture with a specific capacity.
Trait Implementations§
Source§impl Default for RingBufferCapture
impl Default for RingBufferCapture
Source§impl WireTap for RingBufferCapture
impl WireTap for RingBufferCapture
Source§fn on_write(&self, bytes: &[u8], ts: u64)
fn on_write(&self, bytes: &[u8], ts: u64)
poll_write that returns Ok(n) with n > 0.