Add bincode serde support

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/25/head
trivernis 3 years ago
parent bf5a593377
commit 2cc956f1e9
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -31,7 +31,7 @@ jobs:
id: extract_branch id: extract_branch
- name: Run benchmark - name: Run benchmark
run: cargo bench -- --save-baseline ${{steps.extract_branch.outputs.branch}} run: cargo bench --feature serialize_rmp -- --save-baseline ${{steps.extract_branch.outputs.branch}}
- name: upload artifact - name: upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2

@ -33,4 +33,10 @@ jobs:
run: cargo build --verbose run: cargo build --verbose
- name: Run tests - name: Run tests
run: cargo test --verbose run: cargo test --verbose --tests
- name: Run rmp serialization tests
run: cargo test --verbose --all --features serialize_rmp
- name: Run bincode serialization tests
run: cargo test --verbose --all --features serialize_bincode

@ -23,4 +23,4 @@ jobs:
run: cargo login "$CRATES_IO_TOKEN" run: cargo login "$CRATES_IO_TOKEN"
- name: Publish to crates.io - name: Publish to crates.io
run: cargo publish run: cargo publish --all-features

10
Cargo.lock generated

@ -30,6 +30,15 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -41,6 +50,7 @@ name = "bromine"
version = "0.14.0" version = "0.14.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bincode",
"byteorder", "byteorder",
"criterion", "criterion",
"crossbeam-utils", "crossbeam-utils",

@ -28,6 +28,7 @@ byteorder = "1.4.3"
async-trait = "0.1.51" async-trait = "0.1.51"
futures = "0.3.17" futures = "0.3.17"
rmp-serde = {version = "0.15.5", optional = true} rmp-serde = {version = "0.15.5", optional = true}
bincode = {version = "1.3.3", optional = true}
[dependencies.serde] [dependencies.serde]
optional = true optional = true
@ -58,3 +59,4 @@ features = ["macros", "rt-multi-thread"]
default = [] default = []
serialize = ["serde"] serialize = ["serde"]
serialize_rmp = ["serialize", "rmp-serde"] serialize_rmp = ["serialize", "rmp-serde"]
serialize_bincode = ["serialize", "bincode"]

@ -1,4 +1,11 @@
#[cfg(feature = "serialize_rmp")] #[cfg(feature = "serialize_rmp")]
pub mod serialize_rmp; pub mod serialize_rmp;
#[cfg(feature = "serialize_rmp")] #[cfg(feature = "serialize_rmp")]
pub use 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)
}
}

@ -101,6 +101,14 @@
//! # } //! # }
//! ``` //! ```
#[cfg(all(feature = "serialize", not(any(feature = "serialize_bincode", feature = "serialize_rmp"))))]
compile_error!("Feature 'serialize' cannot be used by its own. Choose one of 'serialize_rmp', 'serialize_rmp' instead.");
#[cfg(all(feature = "serialize_rmp", feature = "serialize_bincode"))]
compile_error!(
"Feature 'serialize_rmp' and 'serialize_bincode' cannot be enabled at the same time"
);
pub mod error; pub mod error;
mod events; mod events;
pub mod ipc; pub mod ipc;

Loading…
Cancel
Save