Skip to content

Commit

Permalink
add Address::to_short
Browse files Browse the repository at this point in the history
  • Loading branch information
thvdveld committed Oct 17, 2024
1 parent 45d0ad3 commit 5ff82d8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dot15d4-frame/src/addressing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,25 @@ impl Address {
}
}

/// Return the short address form of the address.
pub fn to_short(&self) -> Option<Self> {
match self {
short @ Address::Short(_) => Some(*short),
Address::Extended(value) => {
let mut raw = [0u8; 2];
raw.copy_from_slice(&value[..2]);
Some(Address::Short(raw))
}
_ => None,
}
}

/// Create a short [`Address`] from an array of 2 bytes.
const fn short_from_bytes(a: [u8; 2]) -> Self {
Self::Short(a)
}

/// Create an extended [`Address`] from an array of 8 bytes.
const fn extended_from_bytes(a: [u8; 8]) -> Self {
Self::Extended(a)
}
Expand Down

0 comments on commit 5ff82d8

Please sign in to comment.