use crate::error::PfcpError;
use crate::ie::{Ie, IeType};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EventNotificationUri {
pub uri: Vec<u8>,
}
impl EventNotificationUri {
pub fn new(uri: impl Into<Vec<u8>>) -> Self {
Self { uri: uri.into() }
}
pub fn marshal(&self) -> Vec<u8> {
self.uri.clone()
}
pub fn unmarshal(data: &[u8]) -> Result<Self, PfcpError> {
if data.is_empty() {
return Err(PfcpError::invalid_length(
"EventNotificationUri",
IeType::EventNotificationUri,
1,
0,
));
}
Ok(Self { uri: data.to_vec() })
}
pub fn to_ie(&self) -> Ie {
Ie::new(IeType::EventNotificationUri, self.marshal())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_round_trip() {
let uri = b"https://nef.example.com/notifications/qos".to_vec();
let original = EventNotificationUri::new(uri);
let parsed = EventNotificationUri::unmarshal(&original.marshal()).unwrap();
assert_eq!(parsed, original);
}
#[test]
fn test_empty_uri_rejected() {
let result = EventNotificationUri::unmarshal(&[]);
assert!(matches!(result, Err(PfcpError::InvalidLength { .. })));
}
#[test]
fn test_to_ie_type() {
let ie = EventNotificationUri::new(b"http://x.example/".to_vec()).to_ie();
assert_eq!(ie.ie_type, IeType::EventNotificationUri);
}
}