Skip to main content

Crate zerodds_flatdata

Crate zerodds_flatdata 

Source
Expand description

FlatStruct trait + slot header for zero-copy same-host pub/sub.

Crate zerodds-flatdata. Safety classification: STANDARD.

Spec: docs/specs/zerodds-flatdata-1.0.md.

§Safety rationale

This crate implements an unsafe trait FlatStruct whose guarantees (Copy + repr(C) + ’static + no pointers/Vec/String) the implementer assures via unsafe impl. The as_bytes / from_bytes_unchecked helpers are then safe by layout — we localize the unsafe island here instead of scattering it into the DataWriter path.

Structs§

FlatReader
Reads FlatStruct samples directly from SHM slots.
FlatSampleRef
Reference sample that holds its source slot for the duration of its lifetime and sets this reader’s bit on Drop (releasing the slot for recycling). Spec §9.2/§9.3. Returned by FlatReader::read_ref.
FlatSlot
Loaned slot. The caller sets the sample via write() and then calls commit(). Dropping without a commit discards the loan.
FlatWriter
Writes FlatStruct samples directly into SHM slots — without CDR encoding.
InMemorySlotAllocator
In-memory slot allocator. Provides the same SlotBackend interface as the POSIX mmap backend (posix.rs), but lives on the process heap — single-process pub/sub and test setups without an mmap dep.
PosixSlotAllocator
POSIX mmap slot allocator. An owner process creates the segment; consumer processes attach via attach.
ShmLocator
SHM locator: all the data a same-host reader needs to attach to a writer SHM segment.
SlotHandle
Slot identification: (segment_id, slot_index).
SlotHeader
Slot header — set by the writer in commit_slot and interpreted by the reader in read_flat.

Enums§

LocatorError
Error during encode/decode.
PosixSlotError
Error while setting up the POSIX segment.
SlotError
Error during slot management.

Constants§

SLOT_HEADER_SIZE
Size of the slot header in bytes.

Traits§

FlatStruct
Marker trait for FlatData-capable types.
SlotBackend
Backend trait for the SHM slot allocator.

Functions§

fnv1a_32
FNV-1a hash of the hostname (32-bit). Set by the writer during discovery; the reader checks it against its own.
is_same_host
Same-host match helper. The caller passes (local hostname, local uid) and a received ShmLocator; returns true when both match — i.e. we can mmap the segment.

Type Aliases§

ReaderMask
Bitmap (32 bit) — one bit per reader slot. Bit set = reader has read. The slot becomes reservable again when all active reader bits are set, or the timeout has elapsed.