mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 15:01:16 +00:00
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:
parent
5cd4f5daeb
commit
08d6386482
@ -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> {
|
pub struct ResourceTemplate<'a> {
|
||||||
children: Vec<&'a dyn Aml>,
|
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]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user