flashbang/message/attributes/
unknown_attributes.rs1use super::*;
2
3pub struct UnknownAttributes {
10 attributes: Vec<u16>,
11}
12
13impl Attribute for UnknownAttributes {
14 const TY: u16 = 0x000A;
15
16 const SIZE: usize = 0;
17
18 fn encode(&self, buf: &mut [u8], offset: usize) {
19 for (i, attr) in self.attributes.iter().enumerate() {
20 let i = i * 2;
21 buf[(i + offset)..(i + 1 + offset)].copy_from_slice(&attr.to_be_bytes());
22 }
23 }
24
25 fn decode(buf: &[u8], meta: &AttributeMeta) -> Self {
26 if meta.len % 2 != 0 {
27 panic!("Each attribute type must be two bytes"); }
29
30 let mut attributes = vec!();
31
32 for i in (meta.offset..(meta.offset + meta.len)).step_by(2) {
33 attributes.push(u16::from_be_bytes(buf[i..(i+1)].try_into().unwrap()));
34 }
35
36 Self {
37 attributes,
38 }
39 }
40
41 fn size(&self) -> usize {
42 self.attributes.len() * 2
43 }
44}