Skip to content

Commit

Permalink
fixup! Always respect DisplayHint::Ascii for byte slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh3Rm4n committed Dec 22, 2020
1 parent a388b26 commit b73795d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,13 @@ fn format_args_real(
Arg::Format { format, args } => buf.push_str(&format_args(format, args, hint)),
Arg::FormatSlice { elements } => {
match hint {
Some(DisplayHint::Ascii) => {
// Filter Ascii Hints, which contains u8 byte slices
Some(DisplayHint::Ascii)
if elements.iter().filter(|e| e.format == "{=u8}").count() != 0 =>
{
let vals = elements
.iter()
// Assumption: Arguments for u8 has always only 1 element
.filter_map(|e| match e.args[0] {
Arg::Uxx(v) => Some(u8::try_from(v).ok()?),
_ => None,
Expand All @@ -1054,9 +1058,7 @@ fn format_args_real(
}
}
}
Arg::Slice(x) => {
format_bytes(x, hint, &mut buf)?
}
Arg::Slice(x) => format_bytes(x, hint, &mut buf)?,
Arg::Char(c) => write!(buf, "{}", c)?,
}
}
Expand Down
4 changes: 3 additions & 1 deletion firmware/qemu/src/bin/log.out
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@
0.000106 INFO b"Hi"
0.000107 INFO b"Hi"
0.000108 INFO b"Hi"
0.000109 INFO QEMU test finished!
0.000109 INFO [45054, 49406]
0.000110 INFO [Data { name: b"Hi", value: true }]
0.000111 INFO QEMU test finished!
4 changes: 3 additions & 1 deletion firmware/qemu/src/bin/log.release.out
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@
0.000104 INFO b"Hi"
0.000105 INFO b"Hi"
0.000106 INFO b"Hi"
0.000107 INFO QEMU test finished!
0.000107 INFO [45054, 49406]
0.000108 INFO [Data { name: b"Hi", value: true }]
0.000109 INFO QEMU test finished!
6 changes: 3 additions & 3 deletions firmware/qemu/src/bin/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ fn main() -> ! {
}

let bytes: &[u8; 2] = b"Hi";
let bytes_u16: &[u16; 2] = &[0xAF_FE, 0xC0_FE];
let array_u16: &[u16; 2] = &[0xAF_FE, 0xC0_FE];

defmt::info!("{=[u8]:a}", *bytes);
defmt::info!("{=[?]:a}", *bytes);
defmt::info!("{:a}", *bytes);
defmt::info!("{=[?]:a}", *bytes_u16);
defmt::info!("{=[?]:a}", *array_u16);

{
#[derive(Format)]
Expand All @@ -555,7 +555,7 @@ fn main() -> ! {
}

let data = &[Data { name: b"Hi", value: true }];
defmt::info!("{=[?]:a}", *data)
defmt::info!("{=[?]:a}", *data);
}

defmt::info!("QEMU test finished!");
Expand Down

0 comments on commit b73795d

Please sign in to comment.