mirror of https://github.com/Trivernis/bromine.git
Add json serde support
Signed-off-by: trivernis <trivernis@protonmail.com>pull/25/head
parent
bb7534d333
commit
67f9ae2b6b
@ -0,0 +1,29 @@
|
||||
use crate::payload::{EventReceivePayload, EventSendPayload};
|
||||
use crate::prelude::IPCResult;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use std::io::Read;
|
||||
|
||||
pub type SerializationError = serde_json::Error;
|
||||
|
||||
impl<T> EventSendPayload for T
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn to_payload_bytes(self) -> IPCResult<Vec<u8>> {
|
||||
let bytes = serde_json::to_vec(&self)?;
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> EventReceivePayload for T
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
fn from_payload_bytes<R: Read>(reader: R) -> IPCResult<Self> {
|
||||
let type_data = serde_json::from_reader(reader)?;
|
||||
|
||||
Ok(type_data)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue