rusmpp_core/values/
broadcast_area_success.rs

1use rusmpp_macros::Rusmpp;
2
3/// The success rate indicator, defined as the ratio of the
4/// number of BTSs that accepted the message and the total
5/// number of BTSs that should have accepted the message, for
6/// a particular broadcast_area_identifier.
7#[repr(u8)]
8#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Rusmpp)]
9#[rusmpp(from_into = skip)]
10#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
11#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
12#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
13pub enum BroadcastAreaSuccess {
14    #[default]
15    InformationNotAvailable,
16    ZeroToHundred(u8),
17    Other(u8),
18}
19
20impl From<BroadcastAreaSuccess> for u8 {
21    fn from(value: BroadcastAreaSuccess) -> Self {
22        match value {
23            BroadcastAreaSuccess::InformationNotAvailable => 255,
24            BroadcastAreaSuccess::ZeroToHundred(value) => value,
25            BroadcastAreaSuccess::Other(value) => value,
26        }
27    }
28}
29
30impl From<u8> for BroadcastAreaSuccess {
31    fn from(value: u8) -> Self {
32        match value {
33            0..=100 => Self::ZeroToHundred(value),
34            255 => Self::InformationNotAvailable,
35            _ => Self::Other(value),
36        }
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn encode_decode() {
46        #[cfg(feature = "alloc")]
47        crate::tests::owned::encode_decode_test_instances::<BroadcastAreaSuccess>();
48        crate::tests::borrowed::encode_decode_test_instances::<BroadcastAreaSuccess>();
49    }
50}