jorgehermo9 commented on code in PR #6366:
URL: https://github.com/apache/opendal/pull/6366#discussion_r2259629862


##########
core/src/layers/foyer.rs:
##########
@@ -0,0 +1,458 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::{
+    future::Future,
+    ops::{Bound, Deref, Range, RangeBounds},
+    sync::Arc,
+};
+
+use foyer::{Code, CodeError, Error as FoyerError, HybridCache};
+
+use crate::raw::oio::*;
+use crate::raw::*;
+use crate::*;
+
+fn extract_err(e: FoyerError) -> Error {
+    let e = match e.downcast::<Error>() {
+        Ok(e) => return e,
+        Err(e) => e,
+    };
+    Error::new(ErrorKind::Unexpected, e.to_string())
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct FoyerKey {
+    pub path: String,
+    pub version: Option<String>,
+}
+
+impl Code for FoyerKey {
+    fn encode(&self, writer: &mut impl std::io::Write) -> 
std::result::Result<(), CodeError> {
+        let path_len = self.path.len() as u64;
+        writer.write_all(&path_len.to_le_bytes())?;
+        writer.write_all(self.path.as_bytes())?;
+        if let Some(ref version) = self.version {
+            let version_len = version.len() as u64;
+            writer.write_all(&version_len.to_le_bytes())?;
+            writer.write_all(version.as_bytes())?;
+        } else {
+            writer.write_all(&0u64.to_le_bytes())?;

Review Comment:
   I'm afraid that we are kind of reimplementing the functionality of 
bincode... Should we really reimplement it to try avoid having a dependency to 
it? I think it would be a lot easier to just forward the struct to bincode 
(this is how the default serializer of `foyer` works, right? if I remember 
correctly, it is behind a feature flag..
   
   The issue of reimplementing is the danger of having such bugs..



-- 
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: commits-unsubscr...@opendal.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to