Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/aml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ impl Aml for Ones {
/// Name/Device/Method/Scope and so on...
pub struct Path {
root: bool,
parent: bool,
name_parts: Vec<[u8; 4]>,
}

impl Aml for Path {
fn to_aml_bytes(&self, sink: &mut dyn AmlSink) {
if self.root {
sink.byte(b'\\');
} else if self.parent {
sink.byte(b'^');
}

match self.name_parts.len() {
Expand All @@ -151,7 +154,9 @@ impl Path {
/// not has 4 bytes will not be accepted.
pub fn new(name: &str) -> Self {
let root = name.starts_with('\\');
let offset = root as usize;
let parent = name.starts_with('^');
let offset = (root || parent) as usize;

let mut name_parts = Vec::new();
for part in name[offset..].split('.') {
assert_eq!(part.len(), 4);
Expand All @@ -160,7 +165,11 @@ impl Path {
name_parts.push(name_part);
}

Path { root, name_parts }
Path {
root,
parent,
name_parts,
}
}
}

Expand Down Expand Up @@ -1995,6 +2004,9 @@ mod tests {
(&"\\_SB_".into() as &Path).to_aml_bytes(&mut aml);
assert_eq!(aml, [0x5C, 0x5F, 0x53, 0x42, 0x5F]);
aml.clear();
(&"^_SB_".into() as &Path).to_aml_bytes(&mut aml);
assert_eq!(aml, [0x5E, 0x5F, 0x53, 0x42, 0x5F]);
aml.clear();
(&"_SB_.COM1".into() as &Path).to_aml_bytes(&mut aml);
assert_eq!(aml, [0x2E, 0x5F, 0x53, 0x42, 0x5F, 0x43, 0x4F, 0x4D, 0x31]);
aml.clear();
Expand Down