1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::{
traits::{Emitable, Parseable},
DecodeError,
NeighbourMessageBuffer,
NEIGHBOUR_HEADER_LEN,
};
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct NeighbourHeader {
pub family: u8,
pub ifindex: u32,
pub state: u16,
pub flags: u8,
pub ntype: u8,
}
impl<T: AsRef<[u8]>> Parseable<NeighbourMessageBuffer<T>> for NeighbourHeader {
fn parse(buf: &NeighbourMessageBuffer<T>) -> Result<Self, DecodeError> {
Ok(Self {
family: buf.family(),
ifindex: buf.ifindex(),
state: buf.state(),
flags: buf.flags(),
ntype: buf.ntype(),
})
}
}
impl Emitable for NeighbourHeader {
fn buffer_len(&self) -> usize {
NEIGHBOUR_HEADER_LEN
}
fn emit(&self, buffer: &mut [u8]) {
let mut packet = NeighbourMessageBuffer::new(buffer);
packet.set_family(self.family);
packet.set_ifindex(self.ifindex);
packet.set_state(self.state);
packet.set_flags(self.flags);
packet.set_ntype(self.ntype);
}
}