pub struct OwnedDialect { /* private fields */ }Expand description
A dialect a caller owns: message shapes looked up by id or name.
This is what makes a whole dialect usable rather than one message at a time. It also
resolves the CRC_EXTRA a Parser needs, so frames from a private
dialect check like any other.
§Examples
use pamoja_mavlink::dialect::{FieldType, MessageDescriptorBuilder, OwnedDialect};
use pamoja_mavlink::{Header, Parser};
let mut dialect = OwnedDialect::new();
dialect.insert(
MessageDescriptorBuilder::new(50_000, "BATTERY_CELLS")
.field("pack_id", FieldType::U8, 0)
.field("uptime_ms", FieldType::U32, 0)
.build()?,
);
let shape = dialect.by_name("BATTERY_CELLS").expect("just inserted");
let frame = shape.with_descriptor(|shape| {
let mut message = pamoja_mavlink::dialect::DynamicMessage::new(shape)?;
message.set_uint("pack_id", 0, 2)?;
message.to_frame(Header::new(9, 1, 0))
})?;
// A parser resolves the seed through the dialect, so the private frame verifies.
let resolve = |id| dialect.crc_extra(id);
let mut parser = Parser::new();
let received = frame
.as_bytes()
.iter()
.filter_map(|byte| parser.push_byte(*byte, &resolve))
.next()
.expect("a whole frame");
assert_eq!(received.message_id(), 50_000);Implementations§
Source§impl OwnedDialect
impl OwnedDialect
Sourcepub fn insert(&mut self, descriptor: OwnedMessageDescriptor)
pub fn insert(&mut self, descriptor: OwnedMessageDescriptor)
Adds a message shape, replacing any shape already held for its id.
§Arguments
descriptor- the shape to add.
Sourcepub fn get(&self, msgid: u32) -> Option<&OwnedMessageDescriptor>
pub fn get(&self, msgid: u32) -> Option<&OwnedMessageDescriptor>
Sourcepub fn by_name(&self, name: &str) -> Option<&OwnedMessageDescriptor>
pub fn by_name(&self, name: &str) -> Option<&OwnedMessageDescriptor>
Trait Implementations§
Source§impl Clone for OwnedDialect
impl Clone for OwnedDialect
Source§fn clone(&self) -> OwnedDialect
fn clone(&self) -> OwnedDialect
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 OwnedDialect
impl Debug for OwnedDialect
Source§impl Default for OwnedDialect
impl Default for OwnedDialect
Source§fn default() -> OwnedDialect
fn default() -> OwnedDialect
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OwnedDialect
impl RefUnwindSafe for OwnedDialect
impl Send for OwnedDialect
impl Sync for OwnedDialect
impl Unpin for OwnedDialect
impl UnsafeUnpin for OwnedDialect
impl UnwindSafe for OwnedDialect
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