netlink_packet_route/link/sriov/
rate.rs
1use netlink_packet_utils::{DecodeError, Emitable, Parseable};
4
5const VF_INFO_RATE_LEN: usize = 12;
6
7#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
8#[non_exhaustive]
9pub struct VfInfoRate {
10 pub vf_id: u32,
11 pub min_tx_rate: u32,
12 pub max_tx_rate: u32,
13}
14
15impl VfInfoRate {
16 pub fn new(vf_id: u32, min_tx_rate: u32, max_tx_rate: u32) -> Self {
17 Self { vf_id, min_tx_rate, max_tx_rate }
18 }
19}
20
21buffer!(VfInfoRateBuffer(VF_INFO_RATE_LEN) {
22 vf_id: (u32, 0..4),
23 min_tx_rate: (u32, 4..8),
24 max_tx_rate: (u32, 8..12)
25});
26
27impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<VfInfoRateBuffer<&'a T>> for VfInfoRate {
28 type Error = DecodeError;
29 fn parse(buf: &VfInfoRateBuffer<&T>) -> Result<Self, DecodeError> {
30 Ok(Self {
31 vf_id: buf.vf_id(),
32 min_tx_rate: buf.min_tx_rate(),
33 max_tx_rate: buf.max_tx_rate(),
34 })
35 }
36}
37
38impl Emitable for VfInfoRate {
39 fn buffer_len(&self) -> usize {
40 VF_INFO_RATE_LEN
41 }
42
43 fn emit(&self, buffer: &mut [u8]) {
44 let mut buffer = VfInfoRateBuffer::new(buffer);
45 buffer.set_vf_id(self.vf_id);
46 buffer.set_min_tx_rate(self.min_tx_rate);
47 buffer.set_max_tx_rate(self.max_tx_rate);
48 }
49}