Function bao::decode::decode_in_place
source · Expand description
Decode a combined mode encoding in place, overwriting the encoded bytes starting from the
beginning of the slice. This returns the number of decoded bytes if successful, or an error if
the encoding doesn’t match the hash
.
If the std
feature is enabled, as it is by default, this will use multiple threads via Rayon.
This function is slower than decode
, however, because only the hashing can be parallelized;
copying the input bytes around has to be done on a single thread.
Example
let input = b"some bytes";
let (hash, mut buffer) = bao::encode::encode_to_vec(input);
let content_len = bao::decode::decode_in_place(&mut buffer, &hash).unwrap();
assert_eq!(input.len(), content_len);
assert_eq!(input, &buffer[..content_len]);