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
// SPDX-License-Identifier: MIT

use netlink_packet_utils::{
    traits::{Emitable, Parseable},
    DecodeError,
};

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[non_exhaustive]
pub struct RouteMfcStats {
    pub packets: u64,
    pub bytes: u64,
    pub wrong_if: u64,
}

const MFC_STATS_LEN: usize = 24;

buffer!(RouteMfcStatsBuffer(MFC_STATS_LEN) {
    packets: (u64, 0..8),
    bytes: (u64, 8..16),
    wrong_if: (u64, 16..24),
});

impl<T: AsRef<[u8]>> Parseable<RouteMfcStatsBuffer<T>> for RouteMfcStats {
    fn parse(
        buf: &RouteMfcStatsBuffer<T>,
    ) -> Result<RouteMfcStats, DecodeError> {
        Ok(RouteMfcStats {
            packets: buf.packets(),
            bytes: buf.bytes(),
            wrong_if: buf.wrong_if(),
        })
    }
}

impl Emitable for RouteMfcStats {
    fn buffer_len(&self) -> usize {
        MFC_STATS_LEN
    }

    fn emit(&self, buffer: &mut [u8]) {
        let mut buffer = RouteMfcStatsBuffer::new(buffer);
        buffer.set_packets(self.packets);
        buffer.set_bytes(self.bytes);
        buffer.set_wrong_if(self.wrong_if);
    }
}