Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update user guide part of the book #616

Merged
merged 5 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [#[global_logger]](./global-logger.md)
- [panic! and assert!](./panic.md)
- [Printers](./printers.md)
- [Encoding](./encoding.md)
- [Design & impl details](./design.md)
- [Interning](./interning.md)
- [Dealing with duplicates](./duplicates.md)
Expand Down
32 changes: 32 additions & 0 deletions book/src/encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Encoding

> 💡 Most users won't need to change the encoding so this section is mainly informative.

`defmt` data can be encoded using one of these 2 formats:

- `rzcobs` - [Reverse Zero-compressing COBS encoding][rzcobs] (rzCOBS). This is the default encoding.
- `raw` - raw data, that is no encoding.

[rzcobs]: https://github.com/Dirbaio/rzcobs

In comparison to not using any encoding, `rzcobs` compresses the data (uses less transport bandwidth),
and adds some degree of error detection thanks to its use of frames.

The encoding is selected via a Cargo feature on the `defmt` crate.
These Cargo features are named `encoding-{encoder_name}`, e.g. `encoding-rzcobs` and `encoding-raw`.

``` toml
[package]
name = "my-application"

[dependencies.defmt]
version = "0.3.0"
features = ["encoding-rzcobs"] # <- encoding
```

Note that libraries (dependencies) MUST not select the encoder so that applications (top-level crates) can.
Urhengulas marked this conversation as resolved.
Show resolved Hide resolved
If no `enocding-*` feature is enabled then the default encoding is used.

The encoding is included in the output binary artifact as metadata so [printers](printers.html) will detect it and use the appropriate decoder automatically.
When the `rzcobs` encoding is used the printers will skip malformed frames (decoding errors) and continue decoding the rest of the `defmt` data.
In contrast, printers handling the `raw` encoding will exit on any decoding error.
2 changes: 1 addition & 1 deletion book/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- `println!`-like formatting
- Multiple logging levels: `error`, `info`, `warn`, `debug`, `trace`
- Crate-level logging level filters
- Compile-time `RUST_LOG`-like filtering of logs: include/omit logging levels with module-level granularity
- Timestamped logs

## Current limitations
Expand Down
8 changes: 4 additions & 4 deletions book/src/istr.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A `Str` value is created using the [`intern!`] macro; the argument to this macro
# extern crate defmt;
let s = "The quick brown fox jumps over the lazy dog";
defmt::info!("{=str}", s);
// ^ bandwidth-use = 43 bytes
// ^ bandwidth-use = 43 bytes

# use defmt::Str;
let interned: Str = defmt::intern!("The quick brown fox jumps over the lazy dog");
Expand All @@ -21,12 +21,12 @@ defmt::info!("{=istr}", interned);

> ⚠️ This was a contrived example to show the difference in bandwidth use.
>
> In practice you should following, which also interns the log string and uses as little bandwidth as the `{=istr}` version:
>
> In practice you should use the following, which also interns the log string and uses as little bandwidth as the `{=istr}` version:
>
> ``` rust
> # extern crate defmt;
> defmt::info!("The quick brown fox jumps over the lazy dog");
> ```

[`defmt::Str`]: https://docs.rs/defmt/*/defmt/struct.Str.html
[`intern!`]: https://docs.rs/defmt/*/defmt/macro.intern.html
[`intern!`]: https://docs.rs/defmt/*/defmt/macro.intern.html