`defmt-print`: Add `fn forward_defmt_frame_to_logger`
@@ -65,15 +65,8 @@ fn main() -> anyhow::Result<()> {
loop {
match table.decode(&frames) {
Ok((frame, consumed)) => {
- let (file, line, mod_path) = obtain_location_info(&locs, &frame, &current_dir);
-
- // Forward the defmt frame to our logger.
- defmt_decoder::log::log_defmt(
- &frame,
- file.as_deref(),
- line,
- mod_path.as_deref(),
- );
+ let location_info = obtain_location_info(&locs, &frame, &current_dir);
+ forward_defmt_frame_to_logger(&frame, location_info);
let num_frames = frames.len();
frames.rotate_left(consumed);
@@ -89,11 +82,13 @@ fn main() -> anyhow::Result<()> {
}
}
+type LocationInfo = (Option<String>, Option<u32>, Option<String>);
+
fn obtain_location_info(
locs: &Option<Locations>,
frame: &Frame,
current_dir: &PathBuf,
-) -> (Option<String>, Option<u32>, Option<String>) {
+) -> LocationInfo {
let (mut file, mut line, mut mod_path) = (None, None, None);
// NOTE(`[]` indexing) all indices in `table` have been verified to exist in the `locs` map
@@ -114,6 +109,11 @@ fn obtain_location_info(
(file, line, mod_path)
}
+fn forward_defmt_frame_to_logger(frame: &Frame, location_info: LocationInfo) {
+ let (file, line, mod_path) = location_info;
+ defmt_decoder::log::log_defmt(&frame, file.as_deref(), line, mod_path.as_deref());
+}
+
/// Report version from Cargo.toml _(e.g. "0.1.4")_ and supported `defmt`-versions.
///
/// Used by `--version` flag.
