mirror of https://github.com/Trivernis/bromine.git
Add bincode serde support
Signed-off-by: trivernis <trivernis@protonmail.com>pull/25/head
parent
bf5a593377
commit
2cc956f1e9
@ -1,4 +1,11 @@
|
||||
#[cfg(feature = "serialize_rmp")]
|
||||
pub mod serialize_rmp;
|
||||
|
||||
#[cfg(feature = "serialize_rmp")]
|
||||
pub use serialize_rmp::*;
|
||||
|
||||
#[cfg(feature = "serialize_bincode")]
|
||||
mod serialize_bincode;
|
||||
|
||||
#[cfg(feature = "serialize_bincode")]
|
||||
pub use serialize_bincode::*;
|
@ -0,0 +1,28 @@
|
||||
use crate::payload::{EventReceivePayload, EventSendPayload};
|
||||
use crate::prelude::IPCResult;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use std::io::Read;
|
||||
|
||||
pub type SerializationError = bincode::Error;
|
||||
|
||||
impl<T> EventSendPayload for T
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn to_payload_bytes(self) -> IPCResult<Vec<u8>> {
|
||||
let bytes = bincode::serialize(&self)?;
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> EventReceivePayload for T
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
fn from_payload_bytes<R: Read>(reader: R) -> IPCResult<Self> {
|
||||
let type_data = bincode::deserialize_from(reader)?;
|
||||
Ok(type_data)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue