rtc_ice/attributes/priority/
mod.rs1#[cfg(test)]
2mod priority_test;
3
4use shared::error::*;
5use stun::attributes::ATTR_PRIORITY;
6use stun::checks::*;
7use stun::message::*;
8
9#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
11pub struct PriorityAttr(pub u32);
12
13const PRIORITY_SIZE: usize = 4; impl Setter for PriorityAttr {
16 fn add_to(&self, m: &mut Message) -> Result<()> {
18 let mut v = vec![0_u8; PRIORITY_SIZE];
19 v.copy_from_slice(&self.0.to_be_bytes());
20 m.add(ATTR_PRIORITY, &v);
21 Ok(())
22 }
23}
24
25impl PriorityAttr {
26 pub fn get_from(&mut self, m: &Message) -> Result<()> {
28 let v = m.get(ATTR_PRIORITY)?;
29
30 check_size(ATTR_PRIORITY, v.len(), PRIORITY_SIZE)?;
31
32 let p = u32::from_be_bytes([v[0], v[1], v[2], v[3]]);
33 self.0 = p;
34
35 Ok(())
36 }
37}