flaneur2020 commented on PR #6366:
URL: https://github.com/apache/opendal/pull/6366#issuecomment-3703398261
> I think foyer has a feature to enable auto-serialization/deserialization
on cache key/values which is based on bincode, so we might don't have to write
any code (I think that is the serde feature? @MrCroxx )
+1, i found there's the following code that had already implement `Code` for
the structs that had `serde::Serialize + serde::de::DeserializeOwned` trait
implmented, so i think all we need is to enable the `"serde"` feature and
derive `serde::Serialize, serde::Deserialize` for `FoyerKey`:
```
#[cfg(feature = "serde")]
impl<T> Code for T
where
T: serde::Serialize + serde::de::DeserializeOwned,
{
fn encode(&self, writer: &mut impl std::io::Write) ->
std::result::Result<(), CodeError> {
bincode::serialize_into(writer, self).map_err(CodeError::from)
}
fn decode(reader: &mut impl std::io::Read) -> std::result::Result<Self,
CodeError> {
bincode::deserialize_from(reader).map_err(CodeError::from)
}
fn estimated_size(&self) -> usize {
bincode::serialized_size(self).unwrap() as usize
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]