Skip to main content

flags

Macro flags 

macro_rules! flags {
    ($name:ty, $bits:ty) => { ... };
}
Expand description

Implements Encode and Decode for a bit mask type.

The type needs a bits method and a from_bits_retain constructor, like the types of the bitflags crate. Decoding keeps unknown bits.

ยงExample

use bytes::Bytes;
use ql_qmi::codec::{Encode, Reader};

/// Technologies of a data call.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Technologies(u32);

impl Technologies {
    pub const fn bits(self) -> u32 {
        self.0
    }

    pub const fn from_bits_retain(bits: u32) -> Self {
        Self(bits)
    }
}

ql_qmi::codec::flags!(Technologies, u32);

let mut out = Vec::new();
Technologies(0x8001).encode(&mut out);
assert_eq!(out, [0x01, 0x80, 0x00, 0x00]);
let decoded: Technologies = Reader::new(Bytes::from(out)).read().unwrap();
assert_eq!(decoded, Technologies(0x8001));