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

Add tracing for logging #93

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Better debug formatter for Input message
  • Loading branch information
caspark committed Dec 18, 2024
commit 618876397c9eb9daafe0b69dadac63bce3478d39
25 changes: 24 additions & 1 deletion src/network/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) struct SyncReply {
pub random_reply: u32, // here's your random data back
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct Input {
pub peer_connect_status: Vec<ConnectionStatus>,
pub disconnect_requested: bool,
Expand All @@ -48,6 +48,29 @@ impl Default for Input {
}
}

impl std::fmt::Debug for Input {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Input")
.field("peer_connect_status", &self.peer_connect_status)
.field("disconnect_requested", &self.disconnect_requested)
.field("start_frame", &self.start_frame)
.field("ack_frame", &self.ack_frame)
.field("bytes", &BytesDebug(&self.bytes))
.finish()
}
}
struct BytesDebug<'a>(&'a [u8]);

impl<'a> std::fmt::Debug for BytesDebug<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("0x")?;
for byte in self.0 {
write!(f, "{:02x}", byte)?;
}
Ok(())
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct InputAck {
pub ack_frame: Frame,
Expand Down
Loading