use bitflags::bitflags;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct UPFunctionFeatures: u16 {
const BUCP = 1 << 0; const DDND = 1 << 1; const DLBD = 1 << 2; const TRST = 1 << 3; const FTUP = 1 << 4; const PFDM = 1 << 5; const HEEU = 1 << 6; const TREU = 1 << 7; const EMPU = 1 << 8; const PDIU = 1 << 9; const UDBC = 1 << 10; const QUOV = 1 << 11; const ADPDP = 1 << 12; const UEIP = 1 << 13; const SSET = 1 << 14; const MPTCP = 1 << 15; }
}
impl UPFunctionFeatures {
pub fn new(features: u16) -> Self {
UPFunctionFeatures::from_bits_truncate(features)
}
pub fn marshal(&self) -> [u8; 2] {
self.bits().to_be_bytes()
}
pub fn unmarshal(data: &[u8]) -> Result<Self, crate::error::PfcpError> {
if data.is_empty() {
return Err(crate::error::PfcpError::invalid_length(
"UP Function Features",
crate::ie::IeType::UpFunctionFeatures,
1,
0,
));
}
let bits = if data.len() == 1 {
u16::from_be_bytes([0, data[0]])
} else {
u16::from_be_bytes([data[0], data[1]])
};
Ok(UPFunctionFeatures::from_bits_truncate(bits))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_up_function_features_marshal_unmarshal() {
let features =
UPFunctionFeatures::BUCP | UPFunctionFeatures::PFDM | UPFunctionFeatures::MPTCP;
let marshaled = features.marshal();
let unmarshaled = UPFunctionFeatures::unmarshal(&marshaled).unwrap();
assert_eq!(features, unmarshaled);
}
}