Struct Message

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

MAVLink message

Implementations§

Source§

impl Message

Source

pub fn builder() -> MessageBuilder

Initiates builder.

Instead of constructor we use builder pattern. An instance of MessageBuilder returned by this function is initialized with default values. Once desired values are set, you can call MessageBuilder::build to obtain Message.

§Examples
use mavinspect::protocol::Message;
use mavinspect::utils::Builder;

let message = Message::builder()
    .set_name("name".to_string())
    .set_description("description")
    .build();

assert!(matches!(message, Message { .. }));
assert_eq!(message.name(), "name");
assert_eq!(message.description(), "description");
Source

pub fn id(&self) -> MessageId

Unique message ID within dialect.

Source

pub fn name(&self) -> &str

Message name

Source

pub fn description(&self) -> &str

Message description.

Source

pub fn fields(&self) -> &[MessageField]

List of message fields.

Source

pub fn get_field_by_name(&self, name: impl AsRef<str>) -> Option<&MessageField>

Returns message field specified by its name if exists.

Source

pub fn wip(&self) -> bool

Work in progress status.

Source

pub fn deprecated(&self) -> Option<&Deprecated>

Deprecation status.

Source

pub fn defined_in(&self) -> &str

Dialect canonical name where this message was finally defined.

We track dialect in which message was defined to help to optimise code generation.

The comprehensive list of dialects where this message was defined can be obtained in Self::appears_in.

Use Self::was_defined_in to check whether message was defined in a specific dialect.

Source

pub fn appears_in(&self) -> &[impl AsRef<str>]

Returns the list of dialect canonical names where this message was defined.

The dialect where the message finally belongs to can be obtained in Self::defined_in.

Use Self::was_defined_in to check whether message was defined in a specific dialect.

Source

pub fn was_defined_in(&self, dialect_canonical_name: impl AsRef<str>) -> bool

Returns true if this message was defined in a dialect with a specified canonical name.

See also: Self::defined_in and Self::appears_in.

Source

pub fn size_v2(&self) -> usize

Size of the fields payload according to MAVLink 2 protocol version.

§Examples
use mavinspect::protocol::{MavType, Message, MessageField};
use mavinspect::utils::Builder;

let msg = Message::builder()
    .set_fields(vec![
        MessageField::builder()
            .set_type(MavType::Array(Box::new(MavType::Float), 3))  // Must be 12
            .build(),
        MessageField::builder()
            .set_type(MavType::Array(Box::new(MavType::UInt8), 5))  // Must be 5
            .build(),
        MessageField::builder()
            .set_type(MavType::Float)                               // Must be 4
            .build(),
    ])
    .build();

assert_eq!(msg.size_v2(), 21);
Source

pub fn size_v1(&self) -> usize

Size of the fields payload according to MAVLink 2 protocol version.

§Examples
use mavinspect::protocol::{MavType, Message, MessageField};
use mavinspect::utils::Builder;

let msg = Message::builder()
    .set_fields(vec![
        MessageField::builder()
            .set_type(MavType::Array(Box::new(MavType::Float), 3))  // Must be 12
            .build(),
        MessageField::builder()
            .set_type(MavType::Array(Box::new(MavType::UInt8), 5))  // Must be 5
            .build(),
        MessageField::builder()
            .set_type(MavType::Float)                               // Ignored
            .set_extension(true)
            .build(),
    ])
    .build();

assert_eq!(msg.size_v1(), 17);
Source

pub fn extension_fields_idx(&self) -> Option<usize>

Returns index of the first extension field if any.

See:

Source

pub fn has_extension_fields(&self) -> bool

Returns whether this message has extension fields.

See:

Source

pub fn fields_v1(&self) -> Vec<&MessageField>

Returns fields applicable to MavLink 1 protocol version.

Basically, as required by specification, all extension fields are excluded.

See: MAVLink message extensions.

Source

pub fn fields_v2(&self) -> Vec<&MessageField>

Returns fields applicable to MAVLink 2 protocol version.

All extension fields will be included.

Fields are reordered according to MAVLink specification

Source

pub fn reordered_fields(&self) -> Vec<&MessageField>

Returns reordered fields according to MAVLink specification.

Source

pub fn base_fields(&self) -> Vec<&MessageField>

Returns base fields.

Base fields are the fields which are not marked as extensions.

These fields are not reordered. To get reordered base fields use Message::fields_v1.

See: MAVLink message extensions.

Source

pub fn base_fields_reordered(&self) -> Vec<&MessageField>

Returns base fields reordered according to MAVLink specification.

Base fields are the fields which are not marked as extensions.

See:

Source

pub fn extension_fields(&self) -> Vec<&MessageField>

Returns extension fields.

See: MAVLink message extensions.

Source

pub fn is_v1_compatible(&self) -> bool

Whether this message is compatible with MAVLink 1.

See: MAVLink versions.

Source

pub fn crc_extra(&self) -> u8

Message CRC_EXTRA calculated from message XML definition.

Calculates CRC for message name and key message fields to detect incompatible changes in message definition.

See: CRC_EXTRA calculation in MAVLink docs.

Source

pub fn fingerprint(&self) -> Fingerprint

Calculates message fingerprint.

A value of opaque type Fingerprint that contains message CRC.

Fingerprint is similar to Self::crc_extra but takes into consideration all fields and all message metadata.

This function calculates a relaxed version of a fingerprint, use Self::fingerprint_strict to take into account MAVLink enums within a dialect.

Source

pub fn fingerprint_strict(&self, dialect: Option<&Dialect>) -> Fingerprint

Calculates message fingerprint.

A value of opaque type Fingerprint that contains dialect CRC.

Fingerprint is similar to Self::crc_extra but takes into consideration all fields and all message metadata.

Calculates a strict version of fingerprint if dialect provided. Use Self::fingerprint to calculate a relaxed fingerprint.

Trait Implementations§

Source§

impl Buildable for Message

Source§

fn to_builder(&self) -> MessageBuilder

Creates MessageBuilder initialised with current message.

§Examples
use mavinspect::protocol::Message;
use mavinspect::utils::{Buildable, Builder};

let original = Message::builder()
    .set_name("original")
    .set_description("original")
    .build();

let updated = original.to_builder()
    .set_description("updated")
    .build();

assert_eq!(updated.name(), "original");
assert_eq!(updated.description(), "updated");
Source§

type Builder = MessageBuilder

Builder for this entity.
Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Message

Source§

fn default() -> Message

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl NamedType for Message

Source§

fn sid() -> SpectaID

Source§

fn named_data_type( type_map: &mut TypeCollection, generics: &[DataType], ) -> NamedDataType

this is equivalent to Type::inline but returns a NamedDataType instead.
Source§

fn definition_named_data_type(type_map: &mut TypeCollection) -> NamedDataType

this is equivalent to [Type::definition] but returns a NamedDataType instead.
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Type for Message

Source§

fn inline(type_map: &mut TypeCollection, generics: Generics<'_>) -> DataType

Returns the definition of a type using the provided generics. Read more
Source§

fn reference(type_map: &mut TypeCollection, generics: &[DataType]) -> Reference

Generates a datatype corresponding to a reference to this type, as determined by its category. Getting a reference to a type implies that it should belong in the type map (since it has to be referenced from somewhere), so the output of definition will be put into the type map.
Source§

impl Flatten for Message

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,