pub struct Ring { /* private fields */ }Expand description
A fixed-capacity, fleet-wide append-only log keyed on KIND byte.
V0 is single-process; V1 is SHM-backed. The API is the same.
Implementations§
Source§impl Ring
impl Ring
Sourcepub fn new<T: OrbitTyped>(capacity: usize) -> Self
pub fn new<T: OrbitTyped>(capacity: usize) -> Self
Create a ring for type T with capacity slots.
Sourcepub fn head(&self) -> u64
pub fn head(&self) -> u64
Monotonic head — number of writes ever performed. Slot index
of the most recent write is (head() - 1) % capacity once
head() > 0.
Sourcepub fn write(
&self,
node_id: NodeId,
frame_kind: u8,
ver: u64,
payload: Bytes,
) -> NetId64
pub fn write( &self, node_id: NodeId, frame_kind: u8, ver: u64, payload: Bytes, ) -> NetId64
Append a frame. Atomically reserves the next counter, mints
the NetId64, and writes the frame into the corresponding
slot. Returns the minted id.
frame_kind is the message class byte (V0: pass 0).
ver is the version / tick at write time (V0: caller’s
choice).
Sourcepub fn read(&self, id: NetId64) -> Option<Frame>
pub fn read(&self, id: NetId64) -> Option<Frame>
Read the slot that the given NetId64’s counter points at.
Returns:
Some(frame)if the slot’s stored id matches the queried id exactly (the slot has not been overwritten by a later writer).Noneif the slot is empty, has wrapped past, or holds a different id than the one asked for.
Sourcepub fn read_head(&self) -> Option<Frame>
pub fn read_head(&self) -> Option<Frame>
Read the most recent frame, regardless of who wrote it. Useful for “what’s the current state?” — ignores counter-by-counter walking.
Sourcepub fn read_at(&self, counter: u64) -> Option<Frame>
pub fn read_at(&self, counter: u64) -> Option<Frame>
Read whatever frame currently occupies the slot at
counter % capacity, regardless of which counter is
stored in it. Used by walking readers that need slot-by-slot
access without knowing the writer’s NetId64 ahead of time.
Returns None if the slot is empty.