pub struct Message { /* private fields */ }
Expand description
MAVLink message
Implementations§
Source§impl Message
impl Message
Sourcepub fn builder() -> MessageBuilder
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");
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Message description.
Sourcepub fn fields(&self) -> &[MessageField]
pub fn fields(&self) -> &[MessageField]
List of message fields.
Sourcepub fn get_field_by_name(&self, name: impl AsRef<str>) -> Option<&MessageField>
pub fn get_field_by_name(&self, name: impl AsRef<str>) -> Option<&MessageField>
Returns message field specified by its name if exists.
Sourcepub fn deprecated(&self) -> Option<&Deprecated>
pub fn deprecated(&self) -> Option<&Deprecated>
Deprecation status.
Sourcepub fn defined_in(&self) -> &str
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.
Sourcepub fn appears_in(&self) -> &[impl AsRef<str>]
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.
Sourcepub fn was_defined_in(&self, dialect_canonical_name: impl AsRef<str>) -> bool
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
.
Sourcepub fn size_v2(&self) -> usize
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);
Sourcepub fn size_v1(&self) -> usize
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);
Sourcepub fn extension_fields_idx(&self) -> Option<usize>
pub fn extension_fields_idx(&self) -> Option<usize>
Returns index of the first extension field if any.
See:
Sourcepub fn has_extension_fields(&self) -> bool
pub fn has_extension_fields(&self) -> bool
Returns whether this message has extension fields.
See:
Sourcepub fn fields_v1(&self) -> Vec<&MessageField>
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.
Sourcepub fn fields_v2(&self) -> Vec<&MessageField>
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
Sourcepub fn reordered_fields(&self) -> Vec<&MessageField>
pub fn reordered_fields(&self) -> Vec<&MessageField>
Returns reordered fields according to MAVLink specification.
Sourcepub fn base_fields(&self) -> Vec<&MessageField>
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
.
Sourcepub fn base_fields_reordered(&self) -> Vec<&MessageField>
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:
Sourcepub fn extension_fields(&self) -> Vec<&MessageField>
pub fn extension_fields(&self) -> Vec<&MessageField>
Returns extension fields.
Sourcepub fn is_v1_compatible(&self) -> bool
pub fn is_v1_compatible(&self) -> bool
Whether this message is compatible with MAVLink 1.
See: MAVLink versions.
Sourcepub fn crc_extra(&self) -> u8
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.
Sourcepub fn fingerprint(&self) -> Fingerprint
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.
Sourcepub fn fingerprint_strict(&self, dialect: Option<&Dialect>) -> Fingerprint
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
impl Buildable for Message
Source§fn to_builder(&self) -> MessageBuilder
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
type Builder = MessageBuilder
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl NamedType for Message
impl NamedType for Message
fn sid() -> SpectaID
Source§fn named_data_type(
type_map: &mut TypeCollection,
generics: &[DataType],
) -> NamedDataType
fn named_data_type( type_map: &mut TypeCollection, generics: &[DataType], ) -> NamedDataType
Source§fn definition_named_data_type(type_map: &mut TypeCollection) -> NamedDataType
fn definition_named_data_type(type_map: &mut TypeCollection) -> NamedDataType
Source§impl Type for Message
impl Type for Message
Source§fn inline(type_map: &mut TypeCollection, generics: Generics<'_>) -> DataType
fn inline(type_map: &mut TypeCollection, generics: Generics<'_>) -> DataType
Source§fn reference(type_map: &mut TypeCollection, generics: &[DataType]) -> Reference
fn reference(type_map: &mut TypeCollection, generics: &[DataType]) -> Reference
definition
will be put into the type map.