From 37049f7ca4a6967d33ceaf67f95f39a0f2c70fac Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 15 Apr 2023 09:43:08 +0700 Subject: [PATCH] Fix bytes remaining on stream --- crates/core/src/bcudp/codex.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/core/src/bcudp/codex.rs b/crates/core/src/bcudp/codex.rs index 74ad60c..747a3ff 100644 --- a/crates/core/src/bcudp/codex.rs +++ b/crates/core/src/bcudp/codex.rs @@ -33,6 +33,15 @@ impl Decoder for BcUdpCodex { type Item = BcUdp; type Error = Error; + /// Since frames can cross EOF boundaries we overload this so it dosen't error if + /// there are bytes left on the stream + fn decode_eof(&mut self, buf: &mut BytesMut) -> Result> { + match self.decode(buf)? { + Some(frame) => Ok(Some(frame)), + None => Ok(None), + } + } + fn decode(&mut self, src: &mut BytesMut) -> Result> { match { BcUdp::deserialize(src) } { Ok(BcUdp::Discovery(UdpDiscovery {