Closed kim closed 3 years ago
I am devastated to realise that the (otherwise really, really good) minicbor
crate is by design not capable of incremental decoding due to its insistence on
avoiding allocations. This is, however, required for decoding from any kind of
IO source (async or not) -- we may frequently receive less bytes than needed to
decode the object, but are forced to repeatedly decode from the start.
The CBOR objects we're dealing with are mostly very small, so it shouldn't be an
issue usually. I'm tempted to add another patch which wraps the recv streams in
a BufRead
nevertheless.
The
futures_codec::Decoder
impl was adapted from the originalserde
-based CBOR decoder tominicbor
. It turns out that this ported over a bug: when the input buffer does not contain enough data, its offset must not be advanced. Otherwise, the next poll will attempt to decode from that offset instead of the start of the object, which will obviously fail.Fixes #648