Skip to main content

EmbeddedRawPublisher

Struct EmbeddedRawPublisher 

Source
pub struct EmbeddedRawPublisher<const TX_BUF: usize = DEFAULT_LOAN_BUF> { /* private fields */ }
Expand description

Typeless publisher handle. Use when the wire format is not ROS CDR (e.g. PX4 uORB raw POD bytes, custom binary protocols).

Two publish paths:

  • publish_raw: user supplies a &[u8], backend memcpys into its outbound buffer. One copy.
  • try_loan: backend (or per-publisher arena fallback) hands user a &mut [u8] slice. User writes in place. PublishLoan::commit triggers the wire write. Zero-copy on backends with native lending (Phase 99: zenoh-pico unstable-zenoh-api, XRCE-DDS); single-memcpy fallback on backends without (uORB).

The const-generic TX_BUF sizes the inline arena slot (default DEFAULT_LOAN_BUF). Loans larger than TX_BUF return LoanError::TooLarge.

Implementations§

Source§

impl<const TX_BUF: usize> EmbeddedRawPublisher<TX_BUF>

Source

pub fn new(handle: RmwPublisher) -> Self

Construct an EmbeddedRawPublisher from a backend-allocated RmwPublisher handle. Public so external extension crates (e.g. nros-px4 for typed uORB wrappers) can wrap a handle they obtained directly from the active session via [crate::Node::session_mut] + a backend-specific create method.

Most users should not call this — use [crate::Node::create_publisher] or [crate::Node::create_publisher_raw] instead.

Source

pub fn supports_event(&self, kind: EventKind) -> bool

Phase 108.A — true if the active backend can fire the named event for this raw publisher.

Source

pub fn publish_raw(&self, data: &[u8]) -> Result<(), NodeError>

Publish a pre-encoded byte slice. The byte format depends entirely on the active RMW backend:

  • zenoh / XRCE-DDS / DDS: CDR-encoded payload including the 4-byte CDR header.
  • uORB: raw POD struct bytes (no header). Length must equal size_of::<T::Msg>() for the registered topic.
Source

pub fn publish_raw_with_attachment( &self, data: &[u8], attachment: &[u8], ) -> Result<(), NodeError>

Phase 128.F.4 — raw publish with a wire-level attachment block.

attachment rides alongside the payload on backends that natively support it (zenoh-pico, Cyclone DDS). Backends without native support silently discard attachment and fall back to the regular publish_raw path — the default Publisher::publish_raw_with_attachment body in nros-rmw does this delegation.

Primary use case: cross-RMW bridges stamp the source backend’s RMW name as bridge_origin so a paired return bridge can drop echoed frames deterministically.

Source

pub fn assert_liveliness(&self) -> Result<(), NodeError>

Phase 108.B — manually assert this publisher’s liveliness. Required for QosLivelinessPolicy::ManualByTopic / ManualByNode. No-op for AUTOMATIC / NONE.

Source

pub fn try_loan(&self, len: usize) -> Result<PublishLoan<'_, TX_BUF>, LoanError>

Reserve a writable slot of len bytes. Caller writes into the returned PublishLoan and calls PublishLoan::commit to publish. Never blocks; returns LoanError::WouldBlock when the slot is already in use (arena fallback) or the backend’s outbound stream is full (lending path), and LoanError::TooLarge when len exceeds the publisher’s slot capacity.

With the rmw-lending cargo feature on, this dispatches to the active backend’s SlotLending::try_lend_slot — zero-copy on backends that natively lend (zenoh-pico via z_bytes_from_static_buf, XRCE-DDS via uxr_prepare_output_stream). Without rmw-lending, the arena fallback is used: caller fills a per-publisher inline slot, commit calls the backend’s publish_raw (single memcpy into the backend’s outbound buffer, same as publish_raw directly).

Source

pub fn loan_with_timeout( &self, len: usize, executor: &mut Executor, timeout: Duration, ) -> Result<PublishLoan<'_, TX_BUF>, LoanError>

Sync blocking loan with timeout. Spins the executor until the arena slot is free or timeout elapses.

Useful when you publish from a sync context that owns the executor and want to block on a busy arena (rare — single-slot arena means contention only when concurrent task tries the same publisher, in which case the offending other task should have committed promptly).

Source

pub fn loan(&self, len: usize) -> LoanFuture<'_, TX_BUF>

Async-await on a free loan slot. Returns the loan as soon as the arena’s busy flag clears (no-lending path) or as soon as the backend’s outbound stream has room (lending path).

Phase 99.H’: cancellation-safe Future. Registers the task’s waker on the arena’s [AtomicWaker] before checking [try_loan]; another task’s commit / discard calls [TxArena::release] which wakes us. Dropping the future before it resolves removes nothing from any wait queue (single-slot AtomicWaker semantics: only the latest registration matters) and explicitly wakes another waiter so the next task in line gets a poll. No PublishLoan is materialised on cancel paths.

Trait Implementations§

Source§

impl<const TX_BUF: usize> Drop for EmbeddedRawPublisher<TX_BUF>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<const TX_BUF: usize = DEFAULT_LOAN_BUF> !Freeze for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize = DEFAULT_LOAN_BUF> !RefUnwindSafe for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize = DEFAULT_LOAN_BUF> !Send for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize = DEFAULT_LOAN_BUF> !Sync for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize> Unpin for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize> UnsafeUnpin for EmbeddedRawPublisher<TX_BUF>

§

impl<const TX_BUF: usize> UnwindSafe for EmbeddedRawPublisher<TX_BUF>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.