Skip to main content

memlink_protocol/
features.rs

1//! Feature flags for protocol capabilities.
2//!
3//! Defines feature flags (STREAMING, BATCHING, PRIORITY_DEGRADATION)
4//! and utility functions for feature bitmap operations.
5
6pub const FEATURE_NONE: u32 = 0;
7
8pub mod feature_flags {
9    pub const STREAMING: u32 = 1 << 0;
10    pub const BATCHING: u32 = 1 << 1;
11    pub const PRIORITY_DEGRADATION: u32 = 1 << 2;
12}
13
14pub use feature_flags::{BATCHING, PRIORITY_DEGRADATION, STREAMING};
15
16pub fn has_feature(features: u32, feature: u32) -> bool {
17    features & feature != 0
18}
19
20pub fn enable_feature(features: u32, feature: u32) -> u32 {
21    features | feature
22}
23
24pub fn disable_feature(features: u32, feature: u32) -> u32 {
25    features & !feature
26}
27
28pub fn intersect_features(a: u32, b: u32) -> u32 {
29    a & b
30}
31
32pub fn union_features(a: u32, b: u32) -> u32 {
33    a | b
34}
35
36pub fn feature_names(features: u32) -> alloc::vec::Vec<&'static str> {
37    let mut names = alloc::vec::Vec::new();
38
39    if has_feature(features, STREAMING) {
40        names.push("STREAMING");
41    }
42    if has_feature(features, BATCHING) {
43        names.push("BATCHING");
44    }
45    if has_feature(features, PRIORITY_DEGRADATION) {
46        names.push("PRIORITY_DEGRADATION");
47    }
48
49    if names.is_empty() {
50        names.push("NONE");
51    }
52
53    names
54}