Skip to content

Commit

Permalink
Added helper macros for parsing bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Apr 30, 2024
1 parent ea145a2 commit 08ebad6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,26 @@ macro_rules! make_simple_globals {
};
}

/// Syntax helper for parsing multi-byte fields into primitives.
///
/// Example: `parse_le!(bytes, i32, 5..9);`
#[macro_export]
macro_rules! parse_le {
($bytes:expr, $t:ty, $range:expr) => {{
<$t>::from_le_bytes($bytes[$range].try_into().unwrap())
}};
}

/// Syntax helper for parsing multi-byte fields into primitives.
///
/// Example: `parse_be!(bytes, i32, 5..9);`
#[macro_export]
macro_rules! parse_be {
($bytes:expr, $t:ty, $range:expr) => {{
<$t>::from_be_bytes($bytes[$range].try_into().unwrap())
}};
}

// todo: Remove this debug_workaroudn function on MCUs that don't require it. Ie, is this required on G4? G0?
#[cfg(not(any(feature = "g0")))]
/// Workaround due to debugger disconnecting in WFI (and low-power) modes.
Expand Down

0 comments on commit 08ebad6

Please sign in to comment.