-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use dynamic serializers/deserializers
- Loading branch information
Showing
20 changed files
with
483 additions
and
204 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
use manul::{ | ||
protocol::{DeserializationError, LocalError}, | ||
session::Format, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use manul::{protocol::LocalError, session::Format}; | ||
use serde::Serialize; | ||
|
||
#[derive(Debug)] | ||
pub struct Bincode; | ||
pub struct Binary; | ||
|
||
impl Format for Bincode { | ||
impl Format for Binary { | ||
fn serialize<T: Serialize>(value: T) -> Result<Box<[u8]>, LocalError> { | ||
bincode::serde::encode_to_vec(value, bincode::config::standard()) | ||
postcard::to_allocvec(&value) | ||
.map(|vec| vec.into()) | ||
.map_err(|err| LocalError::new(err.to_string())) | ||
} | ||
|
||
fn deserialize<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> Result<T, DeserializationError> { | ||
bincode::serde::decode_borrowed_from_slice(bytes, bincode::config::standard()) | ||
.map_err(|err| DeserializationError::new(err.to_string())) | ||
type Des<'de> = postcard::Deserializer<'de, postcard::de_flavors::Slice<'de>>; | ||
|
||
fn deserializer<'de>(bytes: &'de [u8]) -> Self::Des<'de> | ||
where | ||
for<'a> &'a mut Self::Des<'de>: serde::Deserializer<'de>, | ||
{ | ||
postcard::Deserializer::from_flavor(postcard::de_flavors::Slice::new(bytes)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ pub mod simple; | |
#[cfg(test)] | ||
mod simple_malicious; | ||
|
||
pub use format::Bincode; | ||
pub use format::Binary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.