From eb89e468ef3b3aa759b42dff77daaf02bd648232 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Fri, 7 May 2021 14:00:28 -0700 Subject: [PATCH] Ack frame `Debug` implementation This adds a manual `Debug` implementation for Ack frames, to make them understandable in logs. Old: ``` got frame Ack(Ack { largest: 11, delay: 0, additional: b"\x02", ecn: None }) ``` New: ``` got frame Ack(Ack { largest: 9, delay: 0, ecn: None, ranges: "[8..=9]" } ``` --- quinn-proto/src/frame.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/frame.rs b/quinn-proto/src/frame.rs index 1aaa5d7b2..13b6f1de0 100644 --- a/quinn-proto/src/frame.rs +++ b/quinn-proto/src/frame.rs @@ -1,5 +1,6 @@ use std::{ - fmt, io, mem, + fmt::{self, Write}, + io, mem, ops::{Range, RangeInclusive}, }; @@ -324,7 +325,7 @@ impl ApplicationClose { } } -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub struct Ack { pub largest: u64, pub delay: u64, @@ -332,6 +333,28 @@ pub struct Ack { pub ecn: Option, } +impl fmt::Debug for Ack { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut ranges = "[".to_string(); + let mut first = true; + for range in self.iter() { + if !first { + ranges.push(','); + } + write!(ranges, "{:?}", range).unwrap(); + first = false; + } + ranges.push(']'); + + f.debug_struct("Ack") + .field("largest", &self.largest) + .field("delay", &self.delay) + .field("ecn", &self.ecn) + .field("ranges", &ranges) + .finish() + } +} + impl<'a> IntoIterator for &'a Ack { type Item = RangeInclusive; type IntoIter = AckIter<'a>;