Build the raw bytes of a `Boot####` UEFI variable — the on-the-wire form of `EFI_LOAD_OPTION { Attributes, FilePathListLength, Description, FilePathList, OptionalData }`. The description is automatically NUL-terminated in UTF-16LE.
(
attributes: u32,
description: &str,
file_path_nodes: &[DevicePathNode<'_>],
optional_data: &[u8],
)
| 71 | /// |
| 72 | /// The description is automatically NUL-terminated in UTF-16LE. |
| 73 | pub fn boot_option_bytes( |
| 74 | attributes: u32, |
| 75 | description: &str, |
| 76 | file_path_nodes: &[DevicePathNode<'_>], |
| 77 | optional_data: &[u8], |
| 78 | ) -> Vec<u8> { |
| 79 | // Serialise the device-path list first so we know its length. |
| 80 | let mut file_path = Vec::new(); |
| 81 | for node in file_path_nodes { |
| 82 | node.write_to(&mut file_path); |
| 83 | } |
| 84 | |
| 85 | let mut desc = utf16_encode(description); |
| 86 | desc.extend_from_slice(&[0x00, 0x00]); // NUL terminator |
| 87 | |
| 88 | let mut out = Vec::with_capacity(4 + 2 + desc.len() + file_path.len() + optional_data.len()); |
| 89 | out.extend_from_slice(&attributes.to_le_bytes()); |
| 90 | out.extend_from_slice(&(file_path.len() as u16).to_le_bytes()); |
| 91 | out.extend_from_slice(&desc); |
| 92 | out.extend_from_slice(&file_path); |
| 93 | out.extend_from_slice(optional_data); |
| 94 | out |
| 95 | } |
| 96 | |
| 97 | #[cfg(test)] |
| 98 | mod tests { |