pub struct OwnedMessageDescriptor { /* private fields */ }Expand description
A message shape a caller owns, for a message from a dialect this crate does not type.
§Examples
use pamoja_mavlink::dialect::{DynamicMessage, FieldType, MessageDescriptorBuilder};
// A private message, written the way its definition reads: declaration order, with
// the builder putting the fields on the wire largest first.
let shape = MessageDescriptorBuilder::new(50_000, "BATTERY_CELLS")
.field("cell_mv", FieldType::U16, 6)
.field("pack_id", FieldType::U8, 0)
.field("uptime_ms", FieldType::U32, 0)
.build()?;
shape.with_descriptor(|shape| -> Result<(), pamoja_mavlink::MavlinkError> {
// The 32-bit field leads, then the array, then the byte.
assert_eq!(shape.offset_of("uptime_ms"), Some(0));
assert_eq!(shape.offset_of("cell_mv"), Some(4));
assert_eq!(shape.wire_len(), 17);
let mut message = DynamicMessage::new(shape)?;
message.set_uint("cell_mv", 3, 4_150)?;
assert_eq!(message.get_uint("cell_mv", 3)?, 4_150);
Ok(())
})?;Implementations§
Source§impl OwnedMessageDescriptor
impl OwnedMessageDescriptor
Sourcepub fn from_descriptor(descriptor: &MessageDescriptor<'_>) -> Self
pub fn from_descriptor(descriptor: &MessageDescriptor<'_>) -> Self
Sourcepub fn crc_extra(&self) -> u8
pub fn crc_extra(&self) -> u8
Returns the CRC_EXTRA seed this shape implies.
§Returns
The seed, which a frame carrying this message folds into its checksum.
Sourcepub fn fields(&self) -> &[OwnedFieldDescriptor]
pub fn fields(&self) -> &[OwnedFieldDescriptor]
Sourcepub fn with_descriptor<R>(
&self,
query: impl FnOnce(&MessageDescriptor<'_>) -> R,
) -> R
pub fn with_descriptor<R>( &self, query: impl FnOnce(&MessageDescriptor<'_>) -> R, ) -> R
Lends a borrowed view of this shape for the duration of a call.
A MessageDescriptor borrows a slice of fields that does not exist until it is
assembled, so the view is built for the call rather than stored, which keeps this
type free of self-references.
§Arguments
query- what to do with the borrowed shape.
§Returns
Whatever query returns.
Trait Implementations§
Source§impl Clone for OwnedMessageDescriptor
impl Clone for OwnedMessageDescriptor
Source§fn clone(&self) -> OwnedMessageDescriptor
fn clone(&self) -> OwnedMessageDescriptor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OwnedMessageDescriptor
impl Debug for OwnedMessageDescriptor
impl Eq for OwnedMessageDescriptor
Source§impl PartialEq for OwnedMessageDescriptor
impl PartialEq for OwnedMessageDescriptor
Source§fn eq(&self, other: &OwnedMessageDescriptor) -> bool
fn eq(&self, other: &OwnedMessageDescriptor) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for OwnedMessageDescriptor
Auto Trait Implementations§
impl Freeze for OwnedMessageDescriptor
impl RefUnwindSafe for OwnedMessageDescriptor
impl Send for OwnedMessageDescriptor
impl Sync for OwnedMessageDescriptor
impl Unpin for OwnedMessageDescriptor
impl UnsafeUnpin for OwnedMessageDescriptor
impl UnwindSafe for OwnedMessageDescriptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more