pub struct ByteTap { /* private fields */ }Expand description
A positional, non-blocking observer of bytes passing a point in the byte layer. See the module docs.
Implementations§
Source§impl ByteTap
impl ByteTap
Sourcepub fn new(point: TapPoint, capacity: usize) -> Self
pub fn new(point: TapPoint, capacity: usize) -> Self
Create a tap at point with a ring bounded to capacity items.
capacity is a hard cap independent of how fast ByteTap::record
is called or how slowly ByteTap::poll drains it — see the
module docs’s non-blocking trade. Panics if capacity == 0,
which would make every recorded item lost immediately and is almost
certainly a construction mistake rather than an intended tap.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Items currently buffered, awaiting ByteTap::poll. Never exceeds
ByteTap::capacity — useful for a caller that wants to watch a
tap’s backlog before it starts lagging.
Sourcepub fn record(&mut self, bytes: Bytes, at: Timestamp)
pub fn record(&mut self, bytes: Bytes, at: Timestamp)
Producer side: record one observed byte unit with its arrival time.
Never blocks, never errors, never grows the ring past
ByteTap::capacity. When the ring is already full, the oldest
buffered item is evicted to make room and a skip is recorded for the
next ByteTap::poll to report — the producer always completes in
O(1) regardless of whether anything has ever called poll. See the
module docs for why this is the correct trade and what it
costs a slow consumer.
Sourcepub fn poll(&mut self) -> Option<TapItem>
pub fn poll(&mut self) -> Option<TapItem>
Consumer side: pull the next observed item.
Returns TapItem::Lagged first if any items were evicted since the
last poll — a consumer cannot skip past it to reach the data that
follows a gap. Returns None when the ring is empty and no loss is
pending.