twine_codec/radio/
extended_address.rs1const EXTENDED_ADDRESS_SIZE: usize = 8;
9
10pub struct ExtendedAddress([u8; EXTENDED_ADDRESS_SIZE]);
11
12impl ExtendedAddress {
13 pub fn random() -> Self {
14 let mut bytes = [0u8; EXTENDED_ADDRESS_SIZE];
15 crate::fill_random_bytes(&mut bytes);
16 Self(bytes)
17 }
18}
19
20impl From<ExtendedAddress> for u64 {
21 fn from(value: ExtendedAddress) -> Self {
22 u64::from_be_bytes(value.0)
23 }
24}
25
26impl From<u64> for ExtendedAddress {
27 fn from(extended_address: u64) -> Self {
28 Self(extended_address.to_be_bytes())
29 }
30}
31
32impl core::fmt::Display for ExtendedAddress {
33 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34 for byte in &self.0 {
35 write!(f, "{:02x}", byte)?;
36 }
37
38 Ok(())
39 }
40}