@@ -8,19 +8,20 @@ The hint follows the syntax `:Display` and must come after the type within the b
88
99The following display hints are currently supported:
1010
11- | hint | name |
12- | :----- | :------------------------------------------------------- |
13- | ` :x ` | lowercase hexadecimal |
14- | ` :X ` | uppercase hexadecimal |
15- | ` :? ` | ` core::fmt::Debug ` -like |
16- | ` :b ` | binary |
17- | ` :o ` | octal |
18- | ` :a ` | ASCII |
19- | ` :ms ` | timestamp in seconds (input in milliseconds) |
20- | ` :us ` | timestamp in seconds (input in microseconds) |
21- | ` :ts ` | timestamp in human-readable time (input in seconds) |
22- | ` :tms ` | timestamp in human-readable time (input in milliseconds) |
23- | ` :tus ` | timestamp in human-readable time (input in microseconds) |
11+ | hint | name |
12+ | :------ | :------------------------------------------------------- |
13+ | ` :x ` | lowercase hexadecimal |
14+ | ` :X ` | uppercase hexadecimal |
15+ | ` :? ` | ` core::fmt::Debug ` -like |
16+ | ` :b ` | binary |
17+ | ` :o ` | octal |
18+ | ` :a ` | ASCII |
19+ | ` :ms ` | timestamp in seconds (input in milliseconds) |
20+ | ` :us ` | timestamp in seconds (input in microseconds) |
21+ | ` :ts ` | timestamp in human-readable time (input in seconds) |
22+ | ` :tms ` | timestamp in human-readable time (input in milliseconds) |
23+ | ` :tus ` | timestamp in human-readable time (input in microseconds) |
24+ | ` :cbor ` | CBOR encoded items rendered in Diagnostic Notation (EDN) |
2425
2526The first 4 display hints resemble what's supported in ` core::fmt ` , for example:
2627
@@ -44,6 +45,22 @@ let bytes = [104, 101, 255, 108, 108, 111];
4445defmt :: info! (" {=[u8]:a}" , bytes ); // -> INFO b"he\xffllo"
4546```
4647
48+ The CBOR display hint is useful when CBOR data is in memory, especially before further processing:
49+
50+ ``` rust
51+ # extern crate defmt;
52+ # fn parse (slice : & [u8 ]) -> Result <(), ()> {
53+ # Ok (())
54+ # };
55+ # fn main () -> Result <(), ()> {
56+ let id_cred = & [0xa1 , 0x04 , 0x44 , 0x6b , 0x69 , 0x64 , 0x31 ];
57+
58+ defmt :: info! (" Peer ID: {=[u8]:cbor}" , id_cred ); // -> INFO Peer ID: {4: 'kid1'}
59+ let parsed = parse (id_cred )? ;
60+ # parsed
61+ # }
62+ ```
63+
4764## Alternate printing
4865
4966Adding ` # ` in front of a binary, octal, and hexadecimal display hints, precedes these numbers with a base indicator.
0 commit comments