Struct mavinspect::protocol::Filter
source · pub struct Filter { /* private fields */ }
Expand description
Filter options for Dialect
and Protocol
.
Filters messages, commands, and enums by the following filters:
Filter::microservices
: filter by MAVLink microservices. IfFilter::messages
,Filter::enums
, orFilter::commands
are set, then these additional entities will be retained.Filter::messages
: include only specified MAVLink messages.Filter::enums
: include only specified MAVLink enums.Filter::commands
: include only specified MAVLink commands.
In the case of Filter::messages
, Filter::enums
, and Filter::commands
, if Filter::microservices
is
specified, then these entities will be retained in addition to micro-services specification.
Both Filter::messages
, Filter::enums
, and Filter::commands
support wildcards in postfix positions. For
example, *
and MAV_CMD_DO_*
are both valid specifications.
The decision of which enums and their entries to keep is based on whether enum is referenced in
MessageField
or it was referenced by another already included enum in one of the
enum parameters (EnumEntryMavCmdParam
).
Micro-service specifications are similar to filters and have Microservices::messages
, Microservices::enums
,
and Microservices::commands
methods that provide lists of required entities.
§Usage
use mavinspect::protocol::{Filter, Microservices};
/* obtain protocol with `common` dialect */
// Filter
let filtered_protocol = protocol.filtered(
&Filter::by_microservices(Microservices::HEARTBEAT | Microservices::MISSION)
.with_messages(&["FILE_TRANSFER_PROTOCOL"])
.with_enums(&["GIMBAL_DEVICE_CAP_FLAGS"])
.with_commands(&["MAV_CMD_SET_*"])
);
// Let's inspect `common` dialect
let common = filtered_protocol.get_dialect_by_canonical_name("common").unwrap();
// it should contain `HEARTBEAT` messages
assert!(common.contains_message_with_name("HEARTBEAT"));
// and `COMMAND_LONG` message since `MISSION` microservice depends on some commands
assert!(common.contains_message_with_name("COMMAND_LONG"));
// `FILE_TRANSFER_PROTOCOL` (part of file transfer protocol) was explicitly required by `set_messages`
assert!(common.contains_message_with_name("FILE_TRANSFER_PROTOCOL"));
// but these messages should be filtered out
assert!(!common.contains_message_with_name("PROTOCOL_VERSION"));
assert!(!common.contains_message_with_name("CAMERA_TRIGGER"));
// this enum was explicitly requested
assert!(common.contains_enum_with_name("GIMBAL_DEVICE_CAP_FLAGS"));
// since we have commands, then `MAV_CMD` enum should be present
assert!(common.contains_enum_with_name("MAV_CMD"));
// and this command was explicitly requested by `MAV_CMD_SET_*` pattern
assert!(common.contains_command_with_name("MAV_CMD_SET_MESSAGE_INTERVAL"));
// as well as these commands should be present as a part of mission protocol
assert!(common.contains_command_with_name("MAV_CMD_DO_SET_MISSION_CURRENT"));
assert!(common.contains_command_with_name("MAV_CMD_NAV_WAYPOINT"));
// but not these
assert!(!common.contains_command_with_name("MAV_CMD_INJECT_FAILURE"));
assert!(!common.contains_command_with_name("MAV_CMD_GET_HOME_POSITION"));
Implementations§
source§impl Filter
impl Filter
sourcepub fn by_microservices(microservices: Microservices) -> Self
pub fn by_microservices(microservices: Microservices) -> Self
Constructs Filter
that filter by specified microservices
.
sourcepub fn microservices(&self) -> Option<Microservices>
pub fn microservices(&self) -> Option<Microservices>
Microservices to filter.
sourcepub fn with_messages(self, messages: &[impl AsRef<str>]) -> Self
pub fn with_messages(self, messages: &[impl AsRef<str>]) -> Self
Set Self::messages
filter option.
sourcepub fn with_enums(self, enums: &[impl ToString]) -> Self
pub fn with_enums(self, enums: &[impl ToString]) -> Self
Set Self::enums
filter option.
sourcepub fn with_commands(self, commands: &[impl ToString]) -> Self
pub fn with_commands(self, commands: &[impl ToString]) -> Self
Set Self::commands
filter option.
sourcepub fn with_microservices(self, microservices: Microservices) -> Self
pub fn with_microservices(self, microservices: Microservices) -> Self
Set Self::microservices
filter option.