acpi_tables: aml: Add support for strings

Support strings from both static strings (&'static str) and String.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2019-11-04 17:49:33 +00:00 committed by Samuel Ortiz
parent 5cd4f5daeb
commit 08d6386482

View File

@ -285,6 +285,30 @@ impl Aml for Usize {
}
}
fn create_aml_string(v: &str) -> Vec<u8> {
let mut data = Vec::new();
data.push(0x0D); /* String Op */
data.extend_from_slice(v.as_bytes());
data.push(0x0); /* NullChar */
data
}
pub type AmlStr = &'static str;
impl Aml for AmlStr {
fn to_aml_bytes(&self) -> Vec<u8> {
create_aml_string(self)
}
}
pub type AmlString = String;
impl Aml for AmlString {
fn to_aml_bytes(&self) -> Vec<u8> {
create_aml_string(self)
}
}
pub struct ResourceTemplate<'a> {
children: Vec<&'a dyn Aml>,
}
@ -991,4 +1015,16 @@ mod tests {
]
);
}
#[test]
fn test_string() {
assert_eq!(
(&"ACPI" as &dyn Aml).to_aml_bytes(),
[0x0d, b'A', b'C', b'P', b'I', 0]
);
assert_eq!(
"ACPI".to_owned().to_aml_bytes(),
[0x0d, b'A', b'C', b'P', b'I', 0]
);
}
}