Skip to content

Commit

Permalink
storage: add Bincode (de)serializers for readers/writers
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Apr 7, 2024
1 parent 779656f commit b65f2a7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/storage/bincode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ pub fn deserialize<'de, T: serde::Deserialize<'de>>(bytes: &'de [u8]) -> Result<
Ok(BINCODE.deserialize(bytes)?)
}

/// Deserializes a value from a reader using Bincode.
pub fn deserialize_from<R: std::io::Read, T: serde::de::DeserializeOwned>(reader: R) -> Result<T> {
Ok(BINCODE.deserialize_from(reader)?)
}

/// Serializes a value using Bincode.
pub fn serialize<T: serde::Serialize>(value: &T) -> Result<Vec<u8>> {
Ok(BINCODE.serialize(value)?)
}

/// Serializes a value to a writer using Bincode.
pub fn serialize_into<W: std::io::Write, T: serde::Serialize>(writer: W, value: &T) -> Result<()> {
Ok(BINCODE.serialize_into(writer, value)?)
}

0 comments on commit b65f2a7

Please sign in to comment.