debug_assert!(false, ...) prevents error handling
I am sending structs encoded by ssmarshal over serial from a microcontroller to a PC. Due to buffering, a full struct is not always returned, so I keep a list of all bytes that have arrived and periodically try to decode all structs using the following function
fn decode_readings(data: &mut Vec<u8>) -> Result<Vec<data::Reading>, ssmarshal::Error> {
let mut result = vec!();
loop {
match deserialize::<data::Reading>(data) {
Ok((reading, bytes_used)) => {
result.push(reading);
data.drain(0..bytes_used).collect::<Vec<_>>();
},
Err(ssmarshal::Error::EndOfStream) => {
break;
}
Err(e) => {
return Err(e)
}
}
}
Ok(result)
}
However, this crashes in debug mode because the decoder contains a debug_assert!(false, "buffer size too small")
before returning Error::EndOfStream
.
This means that my method of decoding the data that has arrived so far doesn't work
Edited by Frans Skarman