aboutsummaryrefslogtreecommitdiff
path: root/core/src/util/decode.rs
blob: a8a6522d3134d5ee828b2d9a3a157f4c2134e245 (plain)
1
2
3
4
5
6
7
8
9
10
use bincode::Decode;

use crate::Result;

/// Decodes a given type `T` from the given slice. returns the decoded value
/// along with the number of bytes read.
pub fn decode<T: Decode>(src: &[u8]) -> Result<(T, usize)> {
    let (result, bytes_read) = bincode::decode_from_slice(src, bincode::config::standard())?;
    Ok((result, bytes_read))
}