mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-29 02:08:48 -06:00
undo
This commit is contained in:
parent
44088f76e5
commit
dc06305956
|
@ -2,7 +2,6 @@ pub mod client;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub(crate) mod packet;
|
pub(crate) mod packet;
|
||||||
pub(crate) mod common;
|
pub(crate) mod common;
|
||||||
pub(crate) mod serializable;
|
|
||||||
pub use common::ClientId;
|
pub use common::ClientId;
|
||||||
|
|
||||||
//pub(crate) trait Serializable: bincode::Encode + bincode::Decode {}
|
//pub(crate) trait Serializable: bincode::Encode + bincode::Decode {}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use crate::BINCODE_CONFIG;
|
|
||||||
|
|
||||||
pub trait Serializable: bincode::Encode + bincode::Decode {
|
|
||||||
fn serialize(&self, buf: &mut [u8]) -> Result<()>;
|
|
||||||
fn deserialize(buf: &[u8]) -> Result<Self>;
|
|
||||||
|
|
||||||
fn serialize_to_vec(&self) -> Result<Vec<u8>> {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
self.serialize(&mut buf)?;
|
|
||||||
Ok(buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T: bincode::Encode + bincode::Decode> Serializable for T {
|
|
||||||
fn serialize(&self, buf: &mut [u8]) -> Result<()> {
|
|
||||||
bincode::encode_into_slice(self, buf, BINCODE_CONFIG)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn deserialize(buf: &[u8]) -> Result<Self> {
|
|
||||||
bincode::decode_from_slice(buf, BINCODE_CONFIG)?.0
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue