aboutsummaryrefslogtreecommitdiff
path: root/core/src/util/encode.rs
blob: 7d1061b72ecdbd408305759942081adade11c94f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use bincode::Encode;

use crate::Result;

/// Encode the given type `T` into a `Vec<u8>`.
pub fn encode<T: Encode>(msg: &T) -> Result<Vec<u8>> {
    let vec = bincode::encode_to_vec(msg, bincode::config::standard())?;
    Ok(vec)
}

/// Encode the given type `T` into the given slice..
pub fn encode_into_slice<T: Encode>(msg: &T, dst: &mut [u8]) -> Result<()> {
    bincode::encode_into_slice(msg, dst, bincode::config::standard())?;
    Ok(())
}