netlink_packet_route/rtnl/tc/nlas/
stats_basic.rs

1// SPDX-License-Identifier: MIT
2
3use netlink_packet_utils::{
4    traits::{Emitable, Parseable},
5    DecodeError,
6};
7
8/// Byte/Packet throughput statistics
9#[derive(Debug, PartialEq, Eq, Clone, Copy)]
10#[non_exhaustive]
11pub struct StatsBasic {
12    /// number of seen bytes
13    pub bytes: u64,
14    /// number of seen packets
15    pub packets: u32,
16}
17
18pub const STATS_BASIC_LEN: usize = 12;
19
20buffer!(StatsBasicBuffer(STATS_BASIC_LEN) {
21    bytes: (u64, 0..8),
22    packets: (u32, 8..12),
23});
24
25impl<T: AsRef<[u8]>> Parseable<StatsBasicBuffer<T>> for StatsBasic {
26    fn parse(buf: &StatsBasicBuffer<T>) -> Result<Self, DecodeError> {
27        Ok(StatsBasic {
28            bytes: buf.bytes(),
29            packets: buf.packets(),
30        })
31    }
32}
33
34impl Emitable for StatsBasic {
35    fn buffer_len(&self) -> usize {
36        STATS_BASIC_LEN
37    }
38
39    fn emit(&self, buffer: &mut [u8]) {
40        let mut buffer = StatsBasicBuffer::new(buffer);
41        buffer.set_bytes(self.bytes);
42        buffer.set_packets(self.packets);
43    }
44}