fdt_parser/
property.rs

1use core::{ffi::CStr, iter};
2
3use crate::read::FdtReader;
4
5#[derive(Clone)]
6pub struct Property<'a> {
7    pub name: &'a str,
8    pub(crate) data: FdtReader<'a>,
9}
10
11impl<'a> Property<'a> {
12    pub fn raw_value(&self) -> &'a [u8] {
13        self.data.remaining()
14    }
15
16    pub fn u32(&self) -> u32 {
17        self.data.clone().take_u32().unwrap()
18    }
19
20    pub fn u64(&self) -> u64 {
21        self.data.clone().take_u64().unwrap()
22    }
23
24    pub fn str(&self) -> &'a str {
25        CStr::from_bytes_until_nul(self.data.remaining())
26            .unwrap()
27            .to_str()
28            .unwrap()
29    }
30
31    pub fn str_list(&self) -> impl Iterator<Item = &'a str> + 'a {
32        let mut value = self.data.clone();
33        iter::from_fn(move || value.take_str().ok())
34    }
35
36    pub fn u32_list(&self) -> impl Iterator<Item = u32> + 'a {
37        let mut value = self.data.clone();
38        iter::from_fn(move || value.take_u32())
39    }
40
41    pub fn u64_list(&self) -> impl Iterator<Item = u64> + 'a {
42        let mut value = self.data.clone();
43        iter::from_fn(move || value.take_u64())
44    }
45}