Keep defragmented in sync with data length (fixes #639)

This commit is contained in:
Dirkjan Ochtman
2020-02-25 20:13:46 +01:00
committed by Benjamin Saunders
parent 33990db1d5
commit f2fa9cc795
+3 -2
View File
@@ -23,8 +23,7 @@ impl Assembler {
let mut read = 0;
loop {
if self.consume(buf, &mut read) {
self.data.pop();
self.defragmented = self.defragmented.saturating_sub(1);
self.pop();
} else {
break;
}
@@ -113,6 +112,7 @@ impl Assembler {
}
pub(crate) fn pop(&mut self) -> Option<(u64, Bytes)> {
self.defragmented = self.defragmented.saturating_sub(1);
self.data.pop().map(|x| (x.offset, x.bytes))
}
@@ -138,6 +138,7 @@ impl Assembler {
/// Discard all buffered data
pub(crate) fn clear(&mut self) {
self.data.clear();
self.defragmented = 0;
}
}