From dd539df6336a268fe032e5d6703a32c47be73e96 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 23 Oct 2019 11:30:53 +0100 Subject: [PATCH] acpi_tables: sdt: Add ability to add to the table from a slice The generic version does not work in this case as it the size of the the &[u8] is not the size of the slice's contents but how much memory the slice object itself takes up. Signed-off-by: Rob Bradford --- acpi_tables/src/sdt.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/acpi_tables/src/sdt.rs b/acpi_tables/src/sdt.rs index e055f44d1..d3bf65b26 100644 --- a/acpi_tables/src/sdt.rs +++ b/acpi_tables/src/sdt.rs @@ -77,6 +77,14 @@ impl SDT { self.write(orig_length, value); } + pub fn append_slice(&mut self, data: &[u8]) { + let orig_length = self.data.len(); + let new_length = orig_length + data.len(); + self.write_u32(4, new_length as u32); + self.data.extend_from_slice(data); + self.update_checksum(); + } + /// Write a value at the given offset pub fn write(&mut self, offset: usize, value: T) { assert!((offset + (std::mem::size_of::() - 1)) < self.data.len());