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

Enable logging for responses with only alloc. #78

Merged
merged 4 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ pretty_env_logger = "0.4"
goblin = "0.2"

[features]
default = ["std"]
default = ["std", "trace-pkt"]
alloc = ["managed/alloc"]
std = ["alloc"]
trace-pkt = ["alloc"]
paranoid_unsafe = []

# INTERNAL: enables the `__dead_code_marker!` macro.
Expand Down
13 changes: 9 additions & 4 deletions src/protocol/response_writer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(feature = "trace-pkt")]
use alloc::string::String;
#[cfg(feature = "trace-pkt")]
use alloc::vec::Vec;

use num_traits::PrimInt;

use crate::internal::BeBytes;
Expand All @@ -24,7 +29,7 @@ pub struct ResponseWriter<'a, C: Connection + 'a> {
rle_char: u8,
rle_repeat: u8,
// buffer to log outgoing packets. only allocates if logging is enabled.
#[cfg(feature = "std")]
#[cfg(feature = "trace-pkt")]
msg: Vec<u8>,
}

Expand All @@ -37,7 +42,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
checksum: 0,
rle_char: 0,
rle_repeat: 0,
#[cfg(feature = "std")]
#[cfg(feature = "trace-pkt")]
msg: Vec::new(),
}
}
Expand All @@ -51,7 +56,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
// added to the checksum, and is just sitting in the RLE buffer)
let checksum = self.checksum;

#[cfg(feature = "std")]
#[cfg(feature = "trace-pkt")]
trace!(
"--> ${}#{:02x?}",
String::from_utf8_lossy(&self.msg),
Expand All @@ -73,7 +78,7 @@ impl<'a, C: Connection + 'a> ResponseWriter<'a, C> {
}

fn inner_write(&mut self, byte: u8) -> Result<(), Error<C::Error>> {
#[cfg(feature = "std")]
#[cfg(feature = "trace-pkt")]
if log_enabled!(log::Level::Trace) {
match self.msg.as_slice() {
[.., c, b'*'] => {
Expand Down