mavlink-message-definitions 0.6.7

MAVLink message definitions in MAVInspect format
Documentation
//! # MAVLink message definitions for [MAVSpec](https://crates.io/crates/mavspec).
//!
//! <span style="font-size:24px">[🇺🇦](https://mavka.gitlab.io/home/a_note_on_the_war_in_ukraine/)</span>
//! [![`repository`](https://img.shields.io/gitlab/pipeline-status/mavka/libs/mavspec.svg?branch=main&label=repository)](https://gitlab.com/mavka/spec/protocols/mavlink/mavspec-definitions)
//! [![`crates.io`](https://img.shields.io/crates/v/mavlink-message-definitions.svg)](https://crates.io/crates/mavlink-message-definitions)
//! [![`docs.rs`](https://img.shields.io/docsrs/mavlink-message-definitions.svg?label=docs.rs)](https://docs.rs/mavlink-message-definitions/latest/mavlink-message-definitions/)
//! [![`issues`](https://img.shields.io/gitlab/issues/open/mavka/libs/mavspec.svg)](https://gitlab.com/mavka/libs/mavspec/-/issues/)
//!
//! This is a very simple crate with the whole purpose to collect MAVLink
//! [message definitions](https://gitlab.com/mavka/spec/protocols/mavlink/message-definitions-v1.0)
//! using [MAVInspect](https://crates.io/crates/mavinspect). It is used by
//! [MAVSpec](https://crates.io/crates/mavspec) as a source of truth about MAVLink dialect
//! specification.
//!
//! Upstream crates that use [Mavka](https://mavka.gitlab.io/home/) toolchain can use Cargo
//! [patch](https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section)
//! mechanism to replace this crate and therefore change which dialects will be packaged. The latter
//! may be combined with `extra-dialects` feature flag that enforces inclusion of all extra dialects.
//!
//! # Usage
//!
//! > ⚠️ Make sure that you've enabled the ` std ` feature when using this crate without default
//! features.
//!
//! Use [`protocol`] function to get metadata for the entire set of MAVLink dialects.
//!
//! ```rust
//! # #[cfg(not(feature = "dlct-common"))]
//! # fn main() {}
//! # #[cfg(feature = "dlct-common")]
//! # fn main() {
//! let protocol = mavlink_message_definitions::protocol();
//! let common = protocol.get_dialect_by_name("common").unwrap();
//! let heartbeat_message = common.get_message_by_name("HEARTBEAT").unwrap();
//! assert_eq!(heartbeat_message.defined_in(), "minimal");
//! # }
//! ```
//!
//! # Development
//!
//! The main development workflow for this crate involves inclusion into
//! [MAVSpec](https://gitlab.com/mavka/libs/mavspec) as a submodule.
//!
//! # Feature flags
#![doc = document_features::document_features!()]
//
#![warn(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(
    html_logo_url = "https://gitlab.com/mavka/spec/protocols/mavlink/mavspec-definitions/-/raw/main/avatar.png?ref_type=heads",
    html_favicon_url = "https://gitlab.com/mavka/spec/protocols/mavlink/mavspec-definitions/-/raw/main/avatar.png?ref_type=heads"
)]

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
mod std_utils {
    use lazy_static::lazy_static;
    use mavinspect::protocol::Protocol;
    use std::ops::Deref;

    lazy_static! {
    static ref PROTOCOL: Protocol = {
        #[cfg(not(feature = "compress"))]
        return postcard::from_bytes(get_metadata_binary()).unwrap_or_default();
        #[cfg(feature = "compress")]
        {
            let bytes_compressed = get_metadata_binary();
            if let Ok(data) = miniz_oxide::inflate::decompress_to_vec(&bytes_compressed) {
                postcard::from_bytes(data.as_slice()).unwrap_or_default()
            } else {
                Protocol::default()
            }
        }
    };
}

    const fn get_metadata_binary() -> &'static [u8] {
        #[cfg(not(target_os = "windows"))]
        return include_bytes!(concat!(env!("OUT_DIR"), "/", "mavlink-protocol.postcard")).as_slice();
        #[cfg(target_os = "windows")]
        return include_bytes!(concat!(env!("OUT_DIR"), "\\", "mavlink-protocol.postcard")).as_slice();
    }

    /// Metadata for MAVLink dialects generated by [MAVInspect](https://crates.io/crates/mavinspect).
    ///
    /// <section class="warning">
    ///
    /// The first call to this function may take time as it deserializes the entire metadata.
    /// </section>
    pub fn protocol() -> &'static Protocol {
        PROTOCOL.deref()
    }

    /// The sequence of default dialects from the most feature-rich to the most primitive.
    ///
    /// The default dialect set in [`protocol`] will follow one of these values. The library will try
    /// to set the most feature-rich dialect from the available dialects.
    pub const DEFAULT_DIALECT_SEQUENCE: [&str; 5] =
        ["all", "ardupilotmega", "common", "standard", "minimal"];
}

#[cfg(feature = "std")]
pub use std_utils::{protocol, DEFAULT_DIALECT_SEQUENCE};