Fix bytes remaining on stream

This commit is contained in:
Andrew committed 2023-04-16 16:08:44 +07:00
1 parent 8db2fd4a91
commit 37049f7ca4
1 file changed
+9
+9
View File
@@ -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<Option<Self::Item>> {
match self.decode(buf)? {
Some(frame) => Ok(Some(frame)),
None => Ok(None),
}
}
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
match { BcUdp::deserialize(src) } {
Ok(BcUdp::Discovery(UdpDiscovery {