use crate::error::PfcpError;
use crate::ie::{Ie, IeType};
use bitflags::bitflags;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Mbsn4RespFlags: u8 {
const NN19DT = 1 << 0; const JMTI = 1 << 1; const N19DTR = 1 << 2; }
}
impl Mbsn4RespFlags {
pub fn marshal(&self) -> [u8; 1] {
[self.bits()]
}
pub fn unmarshal(data: &[u8]) -> Result<Self, PfcpError> {
if data.is_empty() {
return Err(PfcpError::invalid_length(
"MBSN4 Resp-Flags",
IeType::Mbsn4RespFlags,
1,
0,
));
}
Ok(Mbsn4RespFlags::from_bits_truncate(data[0]))
}
pub fn to_ie(&self) -> Ie {
Ie::new(IeType::Mbsn4RespFlags, self.marshal().to_vec())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_marshal_unmarshal() {
let flags = Mbsn4RespFlags::NN19DT | Mbsn4RespFlags::JMTI | Mbsn4RespFlags::N19DTR;
let parsed = Mbsn4RespFlags::unmarshal(&flags.marshal()).unwrap();
assert_eq!(parsed, flags);
}
#[test]
fn test_unmarshal_empty() {
assert!(matches!(
Mbsn4RespFlags::unmarshal(&[]),
Err(PfcpError::InvalidLength { .. })
));
}
#[test]
fn test_to_ie() {
assert_eq!(
Mbsn4RespFlags::NN19DT.to_ie().ie_type,
IeType::Mbsn4RespFlags
);
}
}