/// A globally unique identifier ([GUID](https://docs.microsoft.com/en-us/windows/win32/api/guiddef/ns-guiddef-guid)) /// used to identify COM and WinRT interfaces. #[repr(C)] #[derive(Clone, Copy, Default, PartialEq, Eq, Hash)] pubstruct GUID { /// Specifies the first 8 hexadecimal digits. pub data1: u32,
/// Specifies the first group of 4 hexadecimal digits. pub data2: u16,
/// Specifies the second group of 4 hexadecimal digits. pub data3: u16,
/// The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12 hexadecimal digits. pub data4: [u8; 8],
}
/// Creates a `GUID` with the given constant values. pubconstfn from_values(data1: u32, data2: u16, data3: u16, data4: [u8; 8]) -> Self { Self {
data1,
data2,
data3,
data4,
}
}
/// Creates a `GUID` from a `u128` value. pubconstfn from_u128(uuid: u128) -> Self { Self {
data1: (uuid >> 96) as u32,
data2: (uuid >> 80 & 0xffff) as u16,
data3: (uuid >> 64 & 0xffff) as u16,
data4: (uuid as u64).to_be_bytes(),
}
}
/// Converts a `GUID` to a `u128` value. pubconstfn to_u128(&self) -> u128 {
((self.data1 as u128) << 96)
+ ((self.data2 as u128) << 80)
+ ((self.data3 as u128) << 64)
+ u64::from_be_bytes(self.data4) as u128
}
/// Creates a `GUID` for a "generic" WinRT type. pubconstfn from_signature(signature: imp::ConstBuffer) -> Self { let data = imp::ConstBuffer::from_slice(&[ 0x11, 0xf4, 0x7a, 0xd5, 0x7b, 0x73, 0x42, 0xc0, 0xab, 0xae, 0x87, 0x8b, 0x1e, 0x16, 0xad, 0xee,
]);
let data = data.push_other(signature);
let bytes = imp::sha1(&data).bytes(); let first = u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]);
let second = u16::from_be_bytes([bytes[4], bytes[5]]); letmut third = u16::from_be_bytes([bytes[6], bytes[7]]);
third = (third & 0x0fff) | (5 << 12); let fourth = (bytes[8] & 0x3f) | 0x80;
let f = bytes.next_u8() * 16 + bytes.next_u8(); let g = bytes.next_u8() * 16 + bytes.next_u8(); let h = bytes.next_u8() * 16 + bytes.next_u8(); let i = bytes.next_u8() * 16 + bytes.next_u8(); let j = bytes.next_u8() * 16 + bytes.next_u8(); let k = bytes.next_u8() * 16 + bytes.next_u8();
Self::from_values(a, b, c, [d, e, f, g, h, i, j, k])
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.