impl IncrementalDecoderIgnore { /// Make a new ignoring decoder. /// /// # Panics /// /// If the amount to ignore is zero. #[must_use] pubfn new(n: usize) -> Self {
assert_ne!(n, 0); Self { remaining: n }
}
let decoder = IncrementalDecoderUint::default(); letmut db = Encoder::from_hex(&self.b); // Add padding so that we can verify that the reader doesn't over-consume.
db.encode_byte(0xff);
for tail in1..db.len() { let split = db.len() - tail; letmut dv = Decoder::from(&db.as_ref()[0..split]);
eprintln!(" split at {split}: {dv:?}");
// Clone the basic decoder for each iteration of the loop. letmut dec = decoder.clone(); letmut res = None; while dv.remaining() > 0 {
res = dec.consume(&mut dv);
}
assert!(dec.min_remaining() < tail);
if tail > 1 {
assert_eq!(res, None);
assert!(dec.min_remaining() > 0); letmut dv = Decoder::from(&db.as_ref()[split..]);
eprintln!(" split remainder {split}: {dv:?}");
res = dec.consume(&mut dv);
assert_eq!(dv.remaining(), 1);
}
#[test] fn ignore() { let db = Encoder::from_hex("12345678ff");
let decoder = IncrementalDecoderIgnore::new(4);
for tail in1..db.len() { let split = db.len() - tail; letmut dv = Decoder::from(&db.as_ref()[0..split]);
eprintln!(" split at {split}: {dv:?}");
// Clone the basic decoder for each iteration of the loop. letmut dec = decoder.clone(); letmut res = dec.consume(&mut dv);
assert_eq!(dv.remaining(), 0);
assert!(dec.min_remaining() < tail);
if tail > 1 {
assert!(!res);
assert!(dec.min_remaining() > 0); letmut dv = Decoder::from(&db.as_ref()[split..]);
eprintln!(" split remainder {split}: {dv:?}");
res = dec.consume(&mut dv);
assert_eq!(dv.remaining(), 1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.