ipmi_rs_core/storage/
mod.rs

1pub mod sel;
2
3use std::num::NonZeroU16;
4
5pub mod sdr;
6
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct Timestamp(u32);
9
10impl core::fmt::Display for Timestamp {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        if self.0 == 0 {
13            write!(f, "Unknown")
14        } else {
15            #[cfg(feature = "time")]
16            {
17                let timestamp = time::OffsetDateTime::from_unix_timestamp(self.0 as i64).unwrap();
18
19                let time = timestamp
20                    .format(&time::format_description::well_known::Rfc3339)
21                    .unwrap();
22
23                write!(f, "{}", time)
24            }
25
26            #[cfg(not(feature = "time"))]
27            write!(f, "{}", self.0)
28        }
29    }
30}
31
32impl From<u32> for Timestamp {
33    fn from(value: u32) -> Self {
34        Self(value)
35    }
36}
37
38#[derive(Debug, Clone)]
39pub struct AllocInfo {
40    pub num_alloc_units: Option<NonZeroU16>,
41    pub alloc_unit_size: Option<NonZeroU16>,
42    pub num_free_units: u16,
43    pub largest_free_blk: u16,
44    pub max_record_size: u8,
45}
46
47impl AllocInfo {
48    pub fn parse(data: &[u8]) -> Option<Self> {
49        if data.len() < 8 {
50            return None;
51        }
52
53        let num_alloc_units = NonZeroU16::new(u16::from_le_bytes([data[0], data[1]]));
54        let alloc_unit_size = NonZeroU16::new(u16::from_le_bytes([data[2], data[3]]));
55        let num_free_units = u16::from_le_bytes([data[4], data[5]]);
56        let largest_free_blk = u16::from_le_bytes([data[6], data[7]]);
57        let max_record_size = data[8];
58
59        Some(Self {
60            num_alloc_units,
61            alloc_unit_size,
62            num_free_units,
63            largest_free_blk,
64            max_record_size,
65        })
66    }
67}