fdt_parser/
property.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use core::ffi::CStr;

use crate::read::FdtReader;

#[derive(Clone)]
pub struct Property<'a> {
    pub name: &'a str,
    pub(crate) data: FdtReader<'a>,
}

impl<'a> Property<'a> {
    pub fn raw_value(&self) -> &'a [u8] {
        self.data.remaining()
    }

    pub fn u32(&self) -> u32 {
        self.data.clone().take_u32().unwrap()
    }

    pub fn u64(&self) -> u64 {
        self.data.clone().take_u64().unwrap()
    }

    pub fn str(&self) -> &'a str {
        CStr::from_bytes_until_nul(self.data.remaining())
            .unwrap()
            .to_str()
            .unwrap()
    }
}