Skip to main content

Dialect

Trait Dialect 

Source
pub trait Dialect {
    type Message;
    type EncodeError: Into<EncoderError>;

    // Required methods
    fn message_id(&self, message: &Self::Message) -> u32;
    fn extra_crc(&self, message_id: u32) -> Option<u8>;
    fn decode(
        &self,
        version: MavlinkVersion,
        message_id: u32,
        payload: &[u8],
    ) -> Result<Self::Message, ParserError>;
    fn encode(
        &self,
        version: MavlinkVersion,
        message: &Self::Message,
        payload: &mut [u8],
    ) -> Result<usize, Self::EncodeError>;
}
Expand description

An instance-backed MAVLink dialect.

Unlike Message, a dialect can obtain its message definitions at runtime. Implementations provide the CRC extra byte required to validate a frame and decode its payload into their message representation.

The generated, compile-time dialect API continues to use Message and is adapted internally to this trait by the reader implementation.

Required Associated Types§

Source

type Message

The representation returned when a message is decoded.

Source

type EncodeError: Into<EncoderError>

Error returned when encoding a message.

Required Methods§

Source

fn message_id(&self, message: &Self::Message) -> u32

MAVLink message ID for an encoded message.

Source

fn extra_crc(&self, message_id: u32) -> Option<u8>

Return the CRC extra byte for message_id, if the message is known.

This lookup is required before decoding because MAVLink incorporates the CRC extra byte into the frame checksum.

Source

fn decode( &self, version: MavlinkVersion, message_id: u32, payload: &[u8], ) -> Result<Self::Message, ParserError>

Decode a validated MAVLink payload.

Source

fn encode( &self, version: MavlinkVersion, message: &Self::Message, payload: &mut [u8], ) -> Result<usize, Self::EncodeError>

Serialize a dialect message payload for the selected MAVLink version.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§