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§
Sourcetype EncodeError: Into<EncoderError>
type EncodeError: Into<EncoderError>
Error returned when encoding a message.
Required Methods§
Sourcefn message_id(&self, message: &Self::Message) -> u32
fn message_id(&self, message: &Self::Message) -> u32
MAVLink message ID for an encoded message.
Sourcefn extra_crc(&self, message_id: u32) -> Option<u8>
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.
Sourcefn decode(
&self,
version: MavlinkVersion,
message_id: u32,
payload: &[u8],
) -> Result<Self::Message, ParserError>
fn decode( &self, version: MavlinkVersion, message_id: u32, payload: &[u8], ) -> Result<Self::Message, ParserError>
Decode a validated MAVLink payload.
Sourcefn encode(
&self,
version: MavlinkVersion,
message: &Self::Message,
payload: &mut [u8],
) -> Result<usize, Self::EncodeError>
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§
Source§impl Dialect for DynamicDialect
Available on crate feature dialect-dynamic only.
impl Dialect for DynamicDialect
dialect-dynamic only.