karyon_core/util/decode.rs
1use bincode::Decode;
2
3use crate::Result;
4
5/// Decodes a given type `T` from the given slice. returns the decoded value
6/// along with the number of bytes read.
7pub fn decode<T: Decode<()>>(src: &[u8]) -> Result<(T, usize)> {
8 let (result, bytes_read) = bincode::decode_from_slice::<T, _>(
9 src,
10 bincode::config::standard().with_fixed_int_encoding(),
11 )?;
12 Ok((result, bytes_read))
13}