From d93be736ef2419728207cb7566a600bd30d52609 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Thu, 12 Dec 2024 13:08:28 +0100 Subject: [PATCH] Fix stats --- io/zenoh-transport/src/common/batch.rs | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/io/zenoh-transport/src/common/batch.rs b/io/zenoh-transport/src/common/batch.rs index 65150f728..0a0a41cf9 100644 --- a/io/zenoh-transport/src/common/batch.rs +++ b/io/zenoh-transport/src/common/batch.rs @@ -363,7 +363,14 @@ impl Encode<&TransportMessage> for &mut WBatch { fn encode(self, x: &TransportMessage) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } } @@ -381,7 +388,14 @@ impl Encode<(&NetworkMessage, &FrameHeader)> for &mut WBatch { fn encode(self, x: (&NetworkMessage, &FrameHeader)) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } } @@ -390,7 +404,14 @@ impl Encode<(&mut ZBufReader<'_>, &mut FragmentHeader)> for &mut WBatch { fn encode(self, x: (&mut ZBufReader<'_>, &mut FragmentHeader)) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } }