My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-core/src/wire/env.rs

20 lines
461 B

use serde::{de::DeserializeOwned, Deserialize, Serialize};
#[repr(C)]
#[derive(Serialize, Deserialize)]
pub struct Envelope {
size: u64,
data: Vec<u8>,
}
impl Envelope {
pub fn pack<T: Serialize>(d: T) -> Self {
let data = bincode::serialize(&d).unwrap();
let size = data.len() as u64;
Self { size, data }
}
pub fn unpack<T: DeserializeOwned>(self) -> T {
bincode::deserialize(&self.data).unwrap()
}
}