Skip to main content

Descriptor

Struct Descriptor 

Source
pub struct Descriptor {
    pub header: DescriptorHeader,
    pub write_ptr: u16,
    pub read_ptr: u16,
    pub capacity: u16,
    pub flags: Flags,
    /* private fields */
}
Expand description

In-memory mirror of the shared CDBG descriptor.

#[repr(C)] keeps the field order matching the on-wire layout documented in the module header, but reads/writes still go through the explicit offset constants below (via volatile helpers) rather than relying on struct layout.

Fields§

§header: DescriptorHeader

Magic + version stamp shared by all Consortium descriptors.

§write_ptr: u16

Writer-owned cursor: byte offset where the next frame will be written.

§read_ptr: u16

Reader-owned cursor: byte offset of the next frame to be read. read_ptr == write_ptr means the ring is empty.

§capacity: u16

Total byte length of the shared region (header + data). Acts as the wrap-around bound for the circular buffer; usable data is [DATA_START, capacity).

§flags: Flags

Writer-owned status flags (e.g. overflow).

Implementations§

Source§

impl Descriptor

Source

pub const fn new(capacity: u16) -> Self

Builds a fresh descriptor for a region of capacity total bytes, with both cursors parked at DATA_START (empty ring) and no flags set.

Source

pub fn check(&self) -> bool

Returns true if the descriptor header has the expected magic and version.

Source

pub unsafe fn from_raw_ptr(ptr: *const u8) -> Self

Reads a Descriptor from shared memory at ptr.

§Safety

ptr must point to a valid, readable shared-memory region of at least DESCRIPTOR_SIZE bytes with consistent volatile layout.

Source

pub unsafe fn write_to_raw_ptr(&self, ptr: *mut u8)

Writes this descriptor to shared memory at ptr.

§Safety

ptr must point to a valid, writable shared-memory region of at least DESCRIPTOR_SIZE bytes.

Source

pub unsafe fn try_read_frame( &mut self, base: *mut u8, buf: &mut [u8], ) -> ReadOutcome

Copies the next available frame’s payload into buf and consumes it.

The one read path: read_one_frame, the host reader, and RingReader all go through it. It allocates nothing, so it serves no_std readers too.

A frame whose payload is longer than buf is left in the ring, unconsumed, and reported as ReadOutcome::TooSmall so the caller can retry with a larger buffer; one of MAX_FRAME_LEN bytes always fits.

§Safety

base must point to the start of the shared-memory region owning this descriptor, valid for at least self.capacity bytes.

Source

pub unsafe fn read_one_frame(&mut self, base: *mut u8) -> Option<Vec<u8>>

Reads the next available defmt frame from the circular buffer, returning its payload.

Returns None if no frame is available or if the current frame header is invalid.

§Safety

base must point to the start of the shared-memory region owning this descriptor, valid for at least self.capacity bytes.

Source

pub unsafe fn read_bulk_frames(&mut self, base: *mut u8) -> Vec<Vec<u8>>

Drains all available defmt frames from the circular buffer, returning them as a Vec.

§Safety

Same requirements as read_one_frame: base must be valid for at least self.capacity bytes.

Source

pub unsafe fn write_one_frame(&mut self, base: *mut u8, frame: &[u8]) -> bool

Writes a single defmt frame into the circular buffer.

Returns true on success; returns false and sets the Overflow flag if the frame does not fit without overwriting unread data.

§Safety

base must point to the start of the shared-memory region owning this descriptor, valid for at least self.capacity bytes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more