Only advance input pointer on complete, successful read of a Value

This commit is contained in:
Tony Garnock-Jones 2019-10-19 23:26:00 +01:00
parent c41fe3df3e
commit 05703d9a35
1 changed files with 6 additions and 4 deletions

View File

@ -103,11 +103,13 @@ impl tokio::codec::Decoder for Codec {
let orig_len = buf.len();
let res = self.codec.decode(&mut buf);
let final_len = buf.len();
bs.advance(orig_len - final_len);
match res {
Ok(v) => match value::from_value(&v) {
Ok(p) => Ok(Some(p)),
Err(e) => Err(DecodeError::Parse(e, v))
Ok(v) => {
bs.advance(orig_len - final_len);
match value::from_value(&v) {
Ok(p) => Ok(Some(p)),
Err(e) => Err(DecodeError::Parse(e, v))
}
}
Err(value::decoder::Error::Eof) => Ok(None),
Err(e) => Err(DecodeError::Read(e)),