-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use cbor instead of json serialization (#746)
Co-authored-by: Mariano A. Nicolini <mariano.nicolini.91@gmail.com>
- Loading branch information
1 parent
8a35c9b
commit 39b08e4
Showing
19 changed files
with
253 additions
and
58 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
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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::io::Read; | ||
|
||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
pub fn cbor_serialize<T: Serialize>(value: &T) -> Result<Vec<u8>, SerializationError> { | ||
let mut buf = Vec::new(); | ||
ciborium::into_writer(value, &mut buf).map_err(|_| SerializationError)?; | ||
Ok(buf) | ||
} | ||
|
||
pub fn cbor_deserialize<R: Read, T: DeserializeOwned>(buf: R) -> Result<T, SerializationError> { | ||
ciborium::from_reader(buf).map_err(|_| SerializationError) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct SerializationError; | ||
|
||
impl std::fmt::Display for SerializationError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "Serialization error") | ||
} | ||
} |
Oops, something went wrong.