#[cfg(test)]
mod priority_test;
use stun::attributes::ATTR_PRIORITY;
use stun::checks::*;
use stun::message::*;
#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
pub struct PriorityAttr(pub u32);
const PRIORITY_SIZE: usize = 4; impl Setter for PriorityAttr {
fn add_to(&self, m: &mut Message) -> Result<(), stun::Error> {
let mut v = vec![0_u8; PRIORITY_SIZE];
v.copy_from_slice(&self.0.to_be_bytes());
m.add(ATTR_PRIORITY, &v);
Ok(())
}
}
impl PriorityAttr {
pub fn get_from(&mut self, m: &Message) -> Result<(), stun::Error> {
let v = m.get(ATTR_PRIORITY)?;
check_size(ATTR_PRIORITY, v.len(), PRIORITY_SIZE)?;
let p = u32::from_be_bytes([v[0], v[1], v[2], v[3]]);
self.0 = p;
Ok(())
}
}