netlink_packet_route/rtnl/tc/nlas/
stats_basic.rs

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