suyanhanx commented on code in PR #3001:
URL: 
https://github.com/apache/incubator-opendal/pull/3001#discussion_r1313203763


##########
bindings/cpp/src/lib.rs:
##########
@@ -56,7 +83,120 @@ impl Operator {
         Ok(self.0.read(path)?)
     }
 
-    fn write(&self, path: &str, bs: &[u8]) -> Result<()> {
-        Ok(self.0.write(path, bs.to_owned())?)
+    // To avoid copying the bytes, we use &'static [u8] here.
+    //
+    // Safety: The bytes created from bs will be dropped after the function 
call.
+    // So it's safe to declare its lifetime as 'static.
+    fn write(&self, path: &str, bs: &'static [u8]) -> Result<()> {
+        Ok(self.0.write(path, bs)?)
+    }
+
+    fn is_exist(&self, path: &str) -> Result<bool> {
+        Ok(self.0.is_exist(path)?)
+    }
+
+    fn create_dir(&self, path: &str) -> Result<()> {
+        Ok(self.0.create_dir(path)?)
+    }
+
+    fn copy(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.copy(src, dst)?)
+    }
+
+    fn rename(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.rename(src, dst)?)
+    }
+
+    // We can't name it to delete because it's a keyword in C++
+    fn remove(&self, path: &str) -> Result<()> {
+        Ok(self.0.delete(path)?)
+    }
+
+    fn stat(&self, path: &str) -> Result<ffi::Metadata> {
+        Ok(self.0.stat(path)?.into())
+    }
+
+    fn list(&self, path: &str) -> Result<Vec<ffi::Entry>> {
+        Ok(self.0.list(path)?.into_iter().map(Into::into).collect())
+    }
+}
+
+impl From<od::Metadata> for ffi::Metadata {
+    fn from(meta: od::Metadata) -> Self {
+        let mut tag = 0u8;

Review Comment:
   Maybe you could add a comment about the usage of this tag?



##########
bindings/cpp/src/lib.rs:
##########
@@ -56,7 +83,120 @@ impl Operator {
         Ok(self.0.read(path)?)
     }
 
-    fn write(&self, path: &str, bs: &[u8]) -> Result<()> {
-        Ok(self.0.write(path, bs.to_owned())?)
+    // To avoid copying the bytes, we use &'static [u8] here.
+    //
+    // Safety: The bytes created from bs will be dropped after the function 
call.
+    // So it's safe to declare its lifetime as 'static.
+    fn write(&self, path: &str, bs: &'static [u8]) -> Result<()> {
+        Ok(self.0.write(path, bs)?)
+    }
+
+    fn is_exist(&self, path: &str) -> Result<bool> {
+        Ok(self.0.is_exist(path)?)
+    }
+
+    fn create_dir(&self, path: &str) -> Result<()> {
+        Ok(self.0.create_dir(path)?)
+    }
+
+    fn copy(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.copy(src, dst)?)
+    }
+
+    fn rename(&self, src: &str, dst: &str) -> Result<()> {
+        Ok(self.0.rename(src, dst)?)
+    }
+
+    // We can't name it to delete because it's a keyword in C++
+    fn remove(&self, path: &str) -> Result<()> {
+        Ok(self.0.delete(path)?)
+    }
+
+    fn stat(&self, path: &str) -> Result<ffi::Metadata> {
+        Ok(self.0.stat(path)?.into())
+    }
+
+    fn list(&self, path: &str) -> Result<Vec<ffi::Entry>> {
+        Ok(self.0.list(path)?.into_iter().map(Into::into).collect())
+    }
+}
+
+impl From<od::Metadata> for ffi::Metadata {
+    fn from(meta: od::Metadata) -> Self {
+        let mut tag = 0u8;
+
+        match meta.mode() {
+            od::EntryMode::FILE => tag |= 0b0000_0001,
+            od::EntryMode::DIR => tag |= 0b0000_0010,
+            _ => {}
+        }
+
+        let content_length = meta.content_length();
+
+        let cache_control = match meta.cache_control() {
+            Some(v) => {
+                tag |= 0b0000_0100;
+                v.to_owned()
+            }
+            None => String::new(),

Review Comment:
   Can we use None or null in cpp?



-- 
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]

Reply via email to