use std::fmt::Write;
use crate::bytes::{le_u16, le_u32};
#[must_use]
pub fn format_guid(raw: &[u8; 16]) -> String {
let d1 = le_u32(raw, 0);
let d2 = le_u16(raw, 4);
let d3 = le_u16(raw, 6);
let mut tail = String::with_capacity(20);
for (i, b) in raw[8..16].iter().enumerate() {
if i == 2 {
tail.push('-');
}
let _ = write!(tail, "{b:02x}");
}
format!("{d1:08x}-{d2:04x}-{d3:04x}-{tail}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn formats_mixed_endian_guid() {
let raw = [
0x3b, 0xd6, 0x67, 0x49, 0x29, 0x2e, 0xd8, 0x4a, 0x83, 0x99, 0xf6, 0xa3, 0x39, 0xe3,
0xd0, 0x01,
];
assert_eq!(format_guid(&raw), "4967d63b-2e29-4ad8-8399-f6a339e3d001");
}
#[test]
fn formats_zero_guid() {
assert_eq!(
format_guid(&[0u8; 16]),
"00000000-0000-0000-0000-000000000000"
);
}
}