-
-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
322eb87
commit 12e92a4
Showing
4 changed files
with
81 additions
and
67 deletions.
There are no files selected for viewing
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,21 @@ | ||
use serde::Serialize; | ||
|
||
/// Serialize a type to CBOR bytes. | ||
/// | ||
/// This trait is implemented for all types that implement `Serialize`. | ||
/// | ||
/// Todo(jon): we want to allocate into one big block per request instead of a bunch of small blocks. | ||
pub trait SerializeCbor { | ||
fn to_cbor_bytes(&self) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>>; | ||
} | ||
|
||
impl<T> SerializeCbor for T | ||
where | ||
T: Serialize, | ||
{ | ||
fn to_cbor_bytes(&self) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>> { | ||
let mut serialized = Vec::new(); | ||
ciborium::into_writer(self, &mut serialized)?; | ||
Ok(serialized) | ||
} | ||
} |
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