Skip to main content

MessageBuilder

Struct MessageBuilder 

Source
pub struct MessageBuilder { /* private fields */ }
Expand description

Submessage aggregator.

Initialized on open with a pre-allocated byte list starting at the RTPS header. Submessages are appended via try_add_submessage; when full the caller must finish() + open a new builder.

Implementations§

Source§

impl MessageBuilder

Source

pub fn open(header: RtpsHeader, targets: Rc<Vec<Locator>>, mtu: usize) -> Self

Opens a new builder with the given RTPS header, targets and MTU budget.

Panics: if mtu is smaller than the RTPS header (20 bytes).

Source

pub fn submsg_count(&self) -> usize

Number of submessages inserted so far.

Source

pub fn is_empty(&self) -> bool

True if the builder contains only the RTPS header.

Source

pub fn len(&self) -> usize

Current total byte count (header + already appended submessages).

Source

pub fn remaining(&self) -> usize

Remaining budget in bytes.

Source

pub fn try_add_submessage( &mut self, id: SubmessageId, flags: u8, body: &[u8], ) -> Result<(), AddError>

Tries to append a submessage. Returns AddError::WouldExceedMtu if it no longer fits — then finish() + a new builder is due.

flags contains only the submessage-specific flags (F, L, Q, H, K, N etc.). The E bit (little-endian) is set by the builder itself, consistently for the whole datagram.

§Errors
Source

pub fn try_add_submessage_split( &mut self, id: SubmessageId, flags: u8, header_body: &[u8], payload_tail: &[u8], ) -> Result<(), AddError>

Like Self::try_add_submessage, but the body in two slices — avoids an intermediate Vec when the caller already has header_body and payload_tail separately. Exactly the hot- path case for the DATA submessage: 20-byte fixed header (the caller writes into a stack buffer) + N byte serializedData (borrowed from the cache Arc<[u8]>). Without this variant the caller needs Vec::with_capacity(20+N) + extend(header) + extend(payload) — a heap alloc + copy of N bytes, which is fully eliminated here. octets_to_next_header = header_body.len() + payload_tail.len().

§Errors

Same as Self::try_add_submessage.

Source

pub fn finish(self) -> Option<OutboundDatagram>

Converts into a finished OutboundDatagram.

Returns None for an empty builder (only the RTPS header without submessages) — this lets callers simply discard unused builders without having to check is_empty() first.

Trait Implementations§

Source§

impl Debug for MessageBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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.