This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new f637cf73e7 feat(bindings/cpp): generate Metadata from core (#9269)
f637cf73e7 is described below

commit f637cf73e730a8333335935d3c95f467409a5dce
Author: Chitral Verma <[email protected]>
AuthorDate: Fri Nov 27 22:33:18 2026 +0530

    feat(bindings/cpp): generate Metadata from core (#9269)
    
    * feat(bindings/cpp): generate Metadata from core
    
    Generate the cxx bridge struct, its conversion from core, the public
    opendal::Metadata class, and the copy between them from the accessors of
    core/core/src/types/metadata.rs, so they no longer drift from core.
    
    The bridge lives in its own nested namespace with its own value structs,
    because lib.rs.h includes its header. The 12 existing public members keep
    their names, types, and declaration order, and content_language and
    user_metadata are appended. Generation fails when core has an accessor
    missing from METADATA_FROZEN_PUBLIC_ORDER, or the list names a member that
    core no longer has.
    
    Add C++ signature checks and a C++17 positional-initialization test taken
    from the pre-change header, a memory round trip for the written fields,
    Rust conversion tests, and an upgrade note for the layout change. Run the
    binding's Rust unit tests in CI.
    
    Part of #9129.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * fix(bindings/cpp): default-initialize appended Metadata members
    
    Give the Metadata members after the 12 hand-written ones a `{}` default
    member initializer, so a positional initializer of the existing members
    stays complete under -Wmissing-field-initializers. The layout and member
    offsets are unchanged.
    
    Test that such an initializer compiles with -Wmissing-field-initializers
    as an error, and that a nonempty Content-Language crosses the bridge. C++
    WriteOptions cannot set Content-Language, so a testing hook writes it from
    Rust.
    
    Document the structured-binding break in upgrade.md, and share the
    frozen-order check between Capability and Metadata.
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    ---------
    
    Signed-off-by: Chitral Verma <[email protected]>
---
 .github/workflows/ci_bindings_cpp.yml         |   5 +
 bindings/cpp/CMakeLists.txt                   |   4 +-
 bindings/cpp/build.rs                         |  11 +-
 bindings/cpp/include/data_structure.hpp       | 156 +----------
 bindings/cpp/include/metadata.hpp             | 157 +++++++++++
 bindings/cpp/src/lib.rs                       |  45 ++--
 bindings/cpp/src/metadata.rs                  | 111 ++++++++
 bindings/cpp/src/operator.cpp                 |  62 +----
 bindings/cpp/src/test_support.rs              |  18 ++
 bindings/cpp/src/types.rs                     | 170 +++++++-----
 bindings/cpp/src/utils/metadata_converter.cpp |  97 +++++++
 bindings/cpp/src/utils/metadata_converter.hpp |  29 +++
 bindings/cpp/tests/metadata_test.cpp          | 184 ++++++++++++-
 bindings/cpp/upgrade.md                       |  29 +++
 dev/src/generate/cpp.rs                       | 358 ++++++++++++++++++++++++--
 dev/src/generate/cpp/metadata_cpp.j2          |  86 +++++++
 dev/src/generate/cpp/metadata_hpp.j2          |  85 ++++++
 dev/src/generate/cpp/metadata_rs.j2           |  76 ++++++
 18 files changed, 1359 insertions(+), 324 deletions(-)

diff --git a/.github/workflows/ci_bindings_cpp.yml 
b/.github/workflows/ci_bindings_cpp.yml
index 30f505bd57..ab49dfab78 100644
--- a/.github/workflows/ci_bindings_cpp.yml
+++ b/.github/workflows/ci_bindings_cpp.yml
@@ -26,6 +26,7 @@ on:
       - main
     paths:
       - "core/core/src/types/capability.rs"
+      - "core/core/src/types/metadata.rs"
       - "dev/src/generate/**"
       - "bindings/cpp/**"
       - "examples/cpp/**"
@@ -64,6 +65,10 @@ jobs:
         working-directory: "bindings/cpp"
         run: cargo clippy -- -D warnings
 
+      - name: Run Rust unit tests
+        working-directory: "bindings/cpp"
+        run: cargo test
+
       - name: Regenerate code from core
         run: |
           cargo run --manifest-path=dev/Cargo.toml -- generate -l cpp
diff --git a/bindings/cpp/CMakeLists.txt b/bindings/cpp/CMakeLists.txt
index 413c0253af..1db63cdba2 100644
--- a/bindings/cpp/CMakeLists.txt
+++ b/bindings/cpp/CMakeLists.txt
@@ -111,8 +111,8 @@ set(CARGO_MANIFEST ${PROJECT_SOURCE_DIR}/Cargo.toml)
 
 # Keep bridge files with the CMake build that selected their Cargo features.
 set(CXX_BRIDGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge)
-set(RUST_BRIDGE_CPP ${CXX_BRIDGE_DIR}/opendal-cpp/src/lib.rs.cc 
${CXX_BRIDGE_DIR}/opendal-cpp/src/capability.rs.cc)
-set(RUST_HEADER_FILE ${CXX_BRIDGE_DIR}/opendal-cpp/src/lib.rs.h 
${CXX_BRIDGE_DIR}/opendal-cpp/src/capability.rs.h ${CXX_BRIDGE_DIR}/rust/cxx.h)
+set(RUST_BRIDGE_CPP ${CXX_BRIDGE_DIR}/opendal-cpp/src/lib.rs.cc 
${CXX_BRIDGE_DIR}/opendal-cpp/src/capability.rs.cc 
${CXX_BRIDGE_DIR}/opendal-cpp/src/metadata.rs.cc)
+set(RUST_HEADER_FILE ${CXX_BRIDGE_DIR}/opendal-cpp/src/lib.rs.h 
${CXX_BRIDGE_DIR}/opendal-cpp/src/capability.rs.h 
${CXX_BRIDGE_DIR}/opendal-cpp/src/metadata.rs.h ${CXX_BRIDGE_DIR}/rust/cxx.h)
 if (OPENDAL_ENABLE_ASYNC)
     list(APPEND RUST_BRIDGE_CPP ${CXX_BRIDGE_DIR}/opendal-cpp/src/async.rs.cc)
     list(APPEND RUST_HEADER_FILE ${CXX_BRIDGE_DIR}/opendal-cpp/src/async.rs.h 
${CXX_BRIDGE_DIR}/rust/cxx_async.h)
diff --git a/bindings/cpp/build.rs b/bindings/cpp/build.rs
index 43cc8229c8..b7956952dd 100644
--- a/bindings/cpp/build.rs
+++ b/bindings/cpp/build.rs
@@ -44,6 +44,8 @@ fn export_bridge(out_dir: &Path, bridge_dir: &Path) -> 
io::Result<()> {
         ("sources", "opendal-cpp/src/capability.rs.cc"),
         ("include", "opendal-cpp/src/lib.rs.h"),
         ("sources", "opendal-cpp/src/lib.rs.cc"),
+        ("include", "opendal-cpp/src/metadata.rs.h"),
+        ("sources", "opendal-cpp/src/metadata.rs.cc"),
     ];
     if cfg!(feature = "async") {
         files.extend([
@@ -63,9 +65,14 @@ fn export_bridge(out_dir: &Path, bridge_dir: &Path) -> 
io::Result<()> {
 
 fn main() -> io::Result<()> {
     let sources = if cfg!(feature = "async") {
-        &["src/capability.rs", "src/lib.rs", "src/async.rs"][..]
+        &[
+            "src/capability.rs",
+            "src/lib.rs",
+            "src/metadata.rs",
+            "src/async.rs",
+        ][..]
     } else {
-        &["src/capability.rs", "src/lib.rs"][..]
+        &["src/capability.rs", "src/lib.rs", "src/metadata.rs"][..]
     };
     let _ = cxx_build::bridges(sources);
 
diff --git a/bindings/cpp/include/data_structure.hpp 
b/bindings/cpp/include/data_structure.hpp
index 90726c3c6b..f430c0efb5 100644
--- a/bindings/cpp/include/data_structure.hpp
+++ b/bindings/cpp/include/data_structure.hpp
@@ -27,164 +27,10 @@
 #include <unordered_map>
 
 #include "capability.hpp"
+#include "metadata.hpp"
 
 namespace opendal {
 
-/**
- * @enum EntryMode
- * @brief The mode of the entry
- */
-enum class EntryMode : int {
-  FILE = 1,
-  DIR = 2,
-  UNKNOWN = 0,
-};
-
-/**
- * @struct Metadata
- * @brief The metadata of a file or directory
- *
- * Metadata contains all the information related to a specific path.
- * Depending on the context of the requests, the metadata for the same path may
- * vary. For example, two versions of the same path might have different 
content
- * lengths. Keep in mind that metadata is always tied to the given context and
- * is not a global state.
- */
-class Metadata {
- public:
-  // Basic file information
-  EntryMode type{EntryMode::UNKNOWN};
-  std::uint64_t content_length{0};
-
-  // HTTP-style headers
-  std::optional<std::string>
-      cache_control;  ///< Cache-Control header as defined by RFC 7234
-  std::optional<std::string>
-      content_disposition;  ///< Content-Disposition header as defined by RFC
-                            ///< 6266
-  std::optional<std::string>
-      content_md5;  ///< Content-MD5 hash (deprecated but widely used)
-  std::optional<std::string>
-      content_type;  ///< Content-Type header as defined by RFC 9110
-  std::optional<std::string>
-      content_encoding;  ///< Content-Encoding header as defined by RFC 7231
-  std::optional<std::string> etag;  ///< ETag header as defined by RFC 7232
-  std::optional<std::chrono::system_clock::time_point>
-      last_modified;  ///< Last-Modified timestamp
-
-  // Versioning information
-  std::optional<std::string>
-      version;                     ///< Version identifier (e.g., S3 version 
ID)
-  std::optional<bool> is_current;  ///< Whether this is the current version
-  bool is_deleted{false};  ///< Whether this entry has been marked as deleted
-
-  // Default constructor
-  Metadata() = default;
-
-  // Destructor
-  ~Metadata() = default;
-
-  // Accessor methods
-
-  /**
-   * @brief Get the entry mode (file type)
-   * @return EntryMode indicating whether this is a file, directory, or unknown
-   */
-  EntryMode Mode() const { return type; }
-
-  /**
-   * @brief Check if this metadata represents a file
-   * @return true if this is a file, false otherwise
-   */
-  bool IsFile() const { return type == EntryMode::FILE; }
-
-  /**
-   * @brief Check if this metadata represents a directory
-   * @return true if this is a directory, false otherwise
-   */
-  bool IsDir() const { return type == EntryMode::DIR; }
-
-  /**
-   * @brief Content length in bytes
-   * @return Content length (0 if not set)
-   */
-  std::uint64_t ContentLength() const { return content_length; }
-
-  /**
-   * @brief Cache control directive
-   * @return Optional cache control string
-   */
-  const std::optional<std::string>& CacheControl() const {
-    return cache_control;
-  }
-
-  /**
-   * @brief Content disposition
-   * @return Optional content disposition string
-   */
-  const std::optional<std::string>& ContentDisposition() const {
-    return content_disposition;
-  }
-
-  /**
-   * @brief Content MD5 hash
-   * @return Optional MD5 hash string
-   */
-  const std::optional<std::string>& ContentMd5() const {
-    return content_md5;
-  }
-
-  /**
-   * @brief Content type (MIME type)
-   * @return Optional content type string
-   */
-  const std::optional<std::string>& ContentType() const {
-    return content_type;
-  }
-
-  /**
-   * @brief Content encoding
-   * @return Optional content encoding string
-   */
-  const std::optional<std::string>& ContentEncoding() const {
-    return content_encoding;
-  }
-
-  /**
-   * @brief ETag
-   * @return Optional ETag string
-   */
-  const std::optional<std::string>& Etag() const { return etag; }
-
-  /**
-   * @brief Last modified timestamp
-   * @return Optional timestamp of last modification
-   */
-  const std::optional<std::chrono::system_clock::time_point>& LastModified()
-      const {
-    return last_modified;
-  }
-
-  /**
-   * @brief Version identifier
-   * @return Optional version string
-   */
-  const std::optional<std::string>& Version() const { return version; }
-
-  /**
-   * @brief Check if this is the current version
-   * @return Optional boolean indicating if this is current (None if versioning
-   * not supported)
-   */
-  const std::optional<bool>& IsCurrent() const { return is_current; }
-
-  /**
-   * @brief Check if this entry has been deleted
-   * @return true if deleted, false otherwise
-   */
-  bool IsDeleted() const { return is_deleted; }
-};
-
 /**
  * @struct Entry
  * @brief The entry of a file or directory
diff --git a/bindings/cpp/include/metadata.hpp 
b/bindings/cpp/include/metadata.hpp
new file mode 100644
index 0000000000..a679c89458
--- /dev/null
+++ b/bindings/cpp/include/metadata.hpp
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ */
+
+// DO NOT EDIT IT MANUALLY. This file is generated by
+// opendal/dev/src/generate/cpp.rs.
+
+#pragma once
+
+#include <chrono>
+#include <cstdint>
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+namespace opendal {
+
+/**
+ * @enum EntryMode
+ * @brief The mode of the entry
+ */
+enum class EntryMode : int {
+  FILE = 1,
+  DIR = 2,
+  UNKNOWN = 0,
+};
+
+/**
+ * @struct Metadata
+ * @brief The metadata of a file or directory
+ *
+ * Metadata contains all the information related to a specific path.
+ * Depending on the context of the requests, the metadata for the same path may
+ * vary. For example, two versions of the same path might have different 
content
+ * lengths. Keep in mind that metadata is always tied to the given context and
+ * is not a global state.
+ */
+class Metadata {
+ public:
+  /// Return this entry's mode.
+  EntryMode type{EntryMode::UNKNOWN};
+  /// Return the full content length of this entry.
+  std::uint64_t content_length{0};
+  /// Return this entry's Cache-Control value.
+  std::optional<std::string> cache_control;
+  /// Return this entry's Content-Disposition value.
+  std::optional<std::string> content_disposition;
+  /// Return this entry's Content-MD5 value.
+  std::optional<std::string> content_md5;
+  /// Return this entry's Content-Type value.
+  std::optional<std::string> content_type;
+  /// Return this entry's Content-Encoding value.
+  std::optional<std::string> content_encoding;
+  /// Return this entry's service-provided ETag as-is.
+  std::optional<std::string> etag;
+  /// Return this entry's Last-Modified timestamp.
+  std::optional<std::chrono::system_clock::time_point> last_modified;
+  /// Return this entry's service-specific version identifier.
+  std::optional<std::string> version;
+  /// Return whether this metadata describes the current object version.
+  std::optional<bool> is_current;
+  /// Return whether this metadata describes a deleted object or delete marker.
+  bool is_deleted{false};
+  /// Return this entry's Content-Language value, if available.
+  std::optional<std::string> content_language{};
+  /// Return this entry's user metadata.
+  std::optional<std::unordered_map<std::string, std::string>> user_metadata{};
+
+  Metadata() = default;
+
+  ~Metadata() = default;
+
+  /// Return this entry's mode.
+  EntryMode Mode() const { return type; }
+
+  /**
+   * @brief Check if this metadata represents a file
+   * @return true if this is a file, false otherwise
+   */
+  bool IsFile() const { return type == EntryMode::FILE; }
+
+  /**
+   * @brief Check if this metadata represents a directory
+   * @return true if this is a directory, false otherwise
+   */
+  bool IsDir() const { return type == EntryMode::DIR; }
+
+  /// Return the full content length of this entry.
+  std::uint64_t ContentLength() const { return content_length; }
+
+  /// Return this entry's Cache-Control value.
+  const std::optional<std::string>& CacheControl() const {
+    return cache_control;
+  }
+
+  /// Return this entry's Content-Disposition value.
+  const std::optional<std::string>& ContentDisposition() const {
+    return content_disposition;
+  }
+
+  /// Return this entry's Content-MD5 value.
+  const std::optional<std::string>& ContentMd5() const { return content_md5; }
+
+  /// Return this entry's Content-Type value.
+  const std::optional<std::string>& ContentType() const { return content_type; 
}
+
+  /// Return this entry's Content-Encoding value.
+  const std::optional<std::string>& ContentEncoding() const {
+    return content_encoding;
+  }
+
+  /// Return this entry's service-provided ETag as-is.
+  const std::optional<std::string>& Etag() const { return etag; }
+
+  /// Return this entry's Last-Modified timestamp.
+  const std::optional<std::chrono::system_clock::time_point>& LastModified()
+      const {
+    return last_modified;
+  }
+
+  /// Return this entry's service-specific version identifier.
+  const std::optional<std::string>& Version() const { return version; }
+
+  /// Return whether this metadata describes the current object version.
+  const std::optional<bool>& IsCurrent() const { return is_current; }
+
+  /// Return whether this metadata describes a deleted object or delete marker.
+  bool IsDeleted() const { return is_deleted; }
+
+  /// Return this entry's Content-Language value, if available.
+  const std::optional<std::string>& ContentLanguage() const {
+    return content_language;
+  }
+
+  /// Return this entry's user metadata.
+  const std::optional<std::unordered_map<std::string, std::string>>&
+  UserMetadata() const {
+    return user_metadata;
+  }
+};
+
+}  // namespace opendal
diff --git a/bindings/cpp/src/lib.rs b/bindings/cpp/src/lib.rs
index 3de04ea41e..32ee0e6bd9 100644
--- a/bindings/cpp/src/lib.rs
+++ b/bindings/cpp/src/lib.rs
@@ -20,6 +20,7 @@ mod r#async;
 mod capability;
 mod layer;
 mod lister;
+mod metadata;
 mod reader;
 mod types;
 mod writer;
@@ -163,43 +164,16 @@ mod ffi {
         End = 2,
     }
 
-    enum EntryMode {
-        File = 1,
-        Dir = 2,
-        Unknown = 0,
-    }
-
     struct OptionalString {
         has_value: bool,
         value: String,
     }
 
-    struct OptionalBool {
-        has_value: bool,
-        value: bool,
-    }
-
     struct OptionalEntry {
         has_value: bool,
         value: Entry,
     }
 
-    struct Metadata {
-        mode: EntryMode,
-        content_length: u64,
-        cache_control: OptionalString,
-        content_disposition: OptionalString,
-        content_md5: OptionalString,
-        content_type: OptionalString,
-        content_encoding: OptionalString,
-        etag: OptionalString,
-        last_modified: OptionalTimestamp,
-        version: OptionalString,
-        is_current: OptionalBool,
-        is_deleted: bool,
-        // Note: content_range and user_metadata are complex types that need 
special handling
-    }
-
     struct Entry {
         path: String,
     }
@@ -210,6 +184,13 @@ mod ffi {
         type Capability = crate::capability::ffi::Capability;
     }
 
+    // Generated from core by `dev/src/generate/cpp.rs`; see src/metadata.rs.
+    unsafe extern "C++" {
+        include!("opendal-cpp/src/metadata.rs.h");
+        #[namespace = "opendal::ffi::metadata"]
+        type Metadata = crate::metadata::ffi::Metadata;
+    }
+
     extern "Rust" {
         type Operator;
         type Reader;
@@ -299,6 +280,11 @@ mod ffi {
         fn new_test_retryable_operator(layers: &LayerBuilder) -> Result<*mut 
Operator>;
         #[cfg(feature = "testing")]
         fn test_retryable_attempt_count() -> u64;
+        #[cfg(feature = "testing")]
+        fn new_test_content_language_operator(
+            path: &str,
+            content_language: &str,
+        ) -> Result<*mut Operator>;
     }
 }
 
@@ -351,6 +337,11 @@ fn test_retryable_attempt_count() -> u64 {
     test_support::retryable_attempt_count() as u64
 }
 
+#[cfg(feature = "testing")]
+fn new_test_content_language_operator(path: &str, content_language: &str) -> 
Result<*mut Operator> {
+    test_support::new_content_language_operator(path, content_language)
+}
+
 unsafe fn delete_operator(op: *mut Operator) {
     if !op.is_null() {
         unsafe {
diff --git a/bindings/cpp/src/metadata.rs b/bindings/cpp/src/metadata.rs
new file mode 100644
index 0000000000..e0cfd80149
--- /dev/null
+++ b/bindings/cpp/src/metadata.rs
@@ -0,0 +1,111 @@
+// 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.
+
+// DO NOT EDIT IT MANUALLY. This file is generated by 
opendal/dev/src/generate/cpp.rs.
+
+/// Shared metadata struct, kept in its own bridge so it can be generated from
+/// core and reused by the main bridge in `lib.rs`.
+///
+/// `lib.rs.h` includes this bridge's header, so this bridge cannot use the
+/// value structs of `lib.rs` and declares its own in a nested namespace.
+#[cxx::bridge(namespace = "opendal::ffi::metadata")]
+pub mod ffi {
+    enum EntryMode {
+        File = 1,
+        Dir = 2,
+        Unknown = 0,
+    }
+
+    struct OptionalBool {
+        has_value: bool,
+        value: bool,
+    }
+
+    struct OptionalString {
+        has_value: bool,
+        value: String,
+    }
+
+    struct OptionalTimestamp {
+        has_value: bool,
+        seconds: i64,
+        nanoseconds: u32,
+    }
+
+    struct HashMapValue {
+        key: String,
+        value: String,
+    }
+
+    struct OptionalUserMetadata {
+        has_value: bool,
+        value: Vec<HashMapValue>,
+    }
+
+    /// Metadata of an entry.
+    struct Metadata {
+        /// Return this entry's mode.
+        mode: EntryMode,
+        /// Return whether this metadata describes the current object version.
+        is_current: OptionalBool,
+        /// Return whether this metadata describes a deleted object or delete 
marker.
+        is_deleted: bool,
+        /// Return this entry's Cache-Control value.
+        cache_control: OptionalString,
+        /// Return the full content length of this entry.
+        content_length: u64,
+        /// Return this entry's Content-MD5 value.
+        content_md5: OptionalString,
+        /// Return this entry's Content-Type value.
+        content_type: OptionalString,
+        /// Return this entry's Content-Encoding value.
+        content_encoding: OptionalString,
+        /// Return this entry's Content-Language value, if available.
+        content_language: OptionalString,
+        /// Return this entry's Last-Modified timestamp.
+        last_modified: OptionalTimestamp,
+        /// Return this entry's service-provided ETag as-is.
+        etag: OptionalString,
+        /// Return this entry's Content-Disposition value.
+        content_disposition: OptionalString,
+        /// Return this entry's service-specific version identifier.
+        version: OptionalString,
+        /// Return this entry's user metadata.
+        user_metadata: OptionalUserMetadata,
+    }
+}
+
+impl From<opendal::Metadata> for ffi::Metadata {
+    fn from(meta: opendal::Metadata) -> Self {
+        Self {
+            mode: meta.mode().into(),
+            is_current: meta.is_current().into(),
+            is_deleted: meta.is_deleted(),
+            cache_control: meta.cache_control().into(),
+            content_length: meta.content_length(),
+            content_md5: meta.content_md5().into(),
+            content_type: meta.content_type().into(),
+            content_encoding: meta.content_encoding().into(),
+            content_language: meta.content_language().into(),
+            last_modified: meta.last_modified().into(),
+            etag: meta.etag().into(),
+            content_disposition: meta.content_disposition().into(),
+            version: meta.version().into(),
+            user_metadata: meta.user_metadata().into(),
+        }
+    }
+}
diff --git a/bindings/cpp/src/operator.cpp b/bindings/cpp/src/operator.cpp
index 304abd2a93..b3d54c63d7 100644
--- a/bindings/cpp/src/operator.cpp
+++ b/bindings/cpp/src/operator.cpp
@@ -25,6 +25,7 @@
 #include "opendal.hpp"
 #include "utils/capability_converter.hpp"
 #include "utils/ffi_converter.hpp"
+#include "utils/metadata_converter.hpp"
 #include "utils/rust_converter.hpp"
 
 namespace opendal {
@@ -197,63 +198,6 @@ const ffi::Operator &CheckedOperator(const ffi::Operator 
*op) {
 
 }  // namespace
 
-std::optional<std::string> parse_optional_string(ffi::OptionalString &&s) {
-  if (s.has_value) {
-    return std::string(std::move(s.value));
-  } else {
-    return std::nullopt;
-  }
-}
-
-std::optional<bool> parse_optional_bool(ffi::OptionalBool &&b) {
-  if (b.has_value) {
-    return b.value;
-  } else {
-    return std::nullopt;
-  }
-}
-
-std::optional<std::chrono::system_clock::time_point> parse_optional_timestamp(
-    ffi::OptionalTimestamp &&ts) {
-  if (!ts.has_value) {
-    return std::nullopt;
-  }
-
-  auto duration = std::chrono::seconds(ts.seconds) +
-                  std::chrono::nanoseconds(ts.nanoseconds);
-  return std::chrono::system_clock::time_point(
-      std::chrono::duration_cast<std::chrono::system_clock::duration>(
-          duration));
-}
-
-Metadata parse_meta_data(ffi::Metadata &&meta) {
-  Metadata metadata;
-
-  // Basic information
-  metadata.type = static_cast<EntryMode>(meta.mode);
-  metadata.content_length = meta.content_length;
-
-  // HTTP-style headers
-  metadata.cache_control = 
parse_optional_string(std::move(meta.cache_control));
-  metadata.content_disposition =
-      parse_optional_string(std::move(meta.content_disposition));
-  metadata.content_md5 = parse_optional_string(std::move(meta.content_md5));
-  metadata.content_type = parse_optional_string(std::move(meta.content_type));
-  metadata.content_encoding =
-      parse_optional_string(std::move(meta.content_encoding));
-  metadata.etag = parse_optional_string(std::move(meta.etag));
-
-  // Versioning information
-  metadata.version = parse_optional_string(std::move(meta.version));
-  metadata.is_current = parse_optional_bool(std::move(meta.is_current));
-  metadata.is_deleted = meta.is_deleted;
-
-  metadata.last_modified =
-      parse_optional_timestamp(std::move(meta.last_modified));
-
-  return metadata;
-}
-
 Operator::Operator() noexcept = default;
 
 void Operator::Destroy() noexcept {
@@ -378,12 +322,12 @@ void Operator::RemoveAll(const std::vector<std::string> 
&paths) {
 }
 
 Metadata Operator::Stat(std::string_view path) {
-  return parse_meta_data(
+  return utils::parse_metadata(
       CheckedOperator(operator_).stat(utils::rust_str(path)));
 }
 
 Metadata Operator::Stat(std::string_view path, const StatOptions &options) {
-  return parse_meta_data(CheckedOperator(operator_).stat_options(
+  return utils::parse_metadata(CheckedOperator(operator_).stat_options(
       utils::rust_str(path), ToFfiOptions(options)));
 }
 
diff --git a/bindings/cpp/src/test_support.rs b/bindings/cpp/src/test_support.rs
index 5522dd358f..d0665ffe3c 100644
--- a/bindings/cpp/src/test_support.rs
+++ b/bindings/cpp/src/test_support.rs
@@ -55,6 +55,24 @@ pub fn new_hanging_operator(layers: &LayerBuilder) -> 
AnyhowResult<*mut Operator
     build_operator(layers, HangingService)
 }
 
+/// Build a memory operator holding an empty `path` with `content_language`,
+/// which the C++ `WriteOptions` cannot set.
+pub fn new_content_language_operator(
+    path: &str,
+    content_language: &str,
+) -> AnyhowResult<*mut Operator> {
+    let op = 
crate::into_blocking_operator(od::Operator::new(od::services::Memory::default())?)?;
+    op.0.write_options(
+        path,
+        Buffer::new(),
+        od::options::WriteOptions {
+            content_language: Some(content_language.to_string()),
+            ..Default::default()
+        },
+    )?;
+    Ok(Box::into_raw(Box::new(op)))
+}
+
 pub fn new_retryable_operator(layers: &LayerBuilder) -> AnyhowResult<*mut 
Operator> {
     reset_retryable_attempts();
     build_operator(
diff --git a/bindings/cpp/src/types.rs b/bindings/cpp/src/types.rs
index 87808630e7..b0e844ab31 100644
--- a/bindings/cpp/src/types.rs
+++ b/bindings/cpp/src/types.rs
@@ -18,38 +18,7 @@
 use opendal as od;
 
 use super::ffi;
-
-impl From<od::Metadata> for ffi::Metadata {
-    fn from(meta: od::Metadata) -> Self {
-        let mode = meta.mode().into();
-        let content_length = meta.content_length();
-        let cache_control = meta.cache_control().map(ToOwned::to_owned).into();
-        let content_disposition = 
meta.content_disposition().map(ToOwned::to_owned).into();
-        let content_md5 = meta.content_md5().map(ToOwned::to_owned).into();
-        let content_type = meta.content_type().map(ToOwned::to_owned).into();
-        let content_encoding = 
meta.content_encoding().map(ToOwned::to_owned).into();
-        let etag = meta.etag().map(ToOwned::to_owned).into();
-        let last_modified = to_ffi_optional_timestamp(meta.last_modified());
-        let version = meta.version().map(ToOwned::to_owned).into();
-        let is_current = meta.is_current().into();
-        let is_deleted = meta.is_deleted();
-
-        Self {
-            mode,
-            content_length,
-            cache_control,
-            content_disposition,
-            content_md5,
-            content_type,
-            content_encoding,
-            etag,
-            last_modified,
-            version,
-            is_current,
-            is_deleted,
-        }
-    }
-}
+use super::metadata::ffi as metadata_ffi;
 
 impl From<od::Entry> for ffi::Entry {
     fn from(entry: od::Entry) -> Self {
@@ -58,7 +27,7 @@ impl From<od::Entry> for ffi::Entry {
     }
 }
 
-impl From<od::EntryMode> for ffi::EntryMode {
+impl From<od::EntryMode> for metadata_ffi::EntryMode {
     fn from(mode: od::EntryMode) -> Self {
         match mode {
             od::EntryMode::FILE => Self::File,
@@ -75,36 +44,38 @@ impl From<od::EntryMode> for ffi::EntryMode {
 /// `Timestamp::subsec_nanosecond` carries the same sign for instants before
 /// the Unix epoch. Normalize them into a floor second and a non-negative
 /// nanosecond so C++ can rebuild the instant with `seconds + nanoseconds`.
-fn to_ffi_optional_timestamp(timestamp: Option<od::raw::Timestamp>) -> 
ffi::OptionalTimestamp {
-    let Some(timestamp) = timestamp else {
-        return ffi::OptionalTimestamp {
-            has_value: false,
-            seconds: 0,
-            nanoseconds: 0,
+impl From<Option<od::raw::Timestamp>> for metadata_ffi::OptionalTimestamp {
+    fn from(timestamp: Option<od::raw::Timestamp>) -> Self {
+        let Some(timestamp) = timestamp else {
+            return Self {
+                has_value: false,
+                seconds: 0,
+                nanoseconds: 0,
+            };
         };
-    };
-
-    let timestamp = timestamp.into_inner();
-    let mut seconds = timestamp.as_second();
-    let mut nanoseconds = timestamp.subsec_nanosecond();
-    if nanoseconds < 0 {
-        seconds -= 1;
-        nanoseconds += 1_000_000_000;
-    }
 
-    ffi::OptionalTimestamp {
-        has_value: true,
-        seconds,
-        nanoseconds: nanoseconds as u32,
+        let timestamp = timestamp.into_inner();
+        let mut seconds = timestamp.as_second();
+        let mut nanoseconds = timestamp.subsec_nanosecond();
+        if nanoseconds < 0 {
+            seconds -= 1;
+            nanoseconds += 1_000_000_000;
+        }
+
+        Self {
+            has_value: true,
+            seconds,
+            nanoseconds: nanoseconds as u32,
+        }
     }
 }
 
-impl From<Option<String>> for ffi::OptionalString {
-    fn from(s: Option<String>) -> Self {
+impl From<Option<&str>> for metadata_ffi::OptionalString {
+    fn from(s: Option<&str>) -> Self {
         match s {
             Some(s) => Self {
                 has_value: true,
-                value: s,
+                value: s.to_owned(),
             },
             None => Self {
                 has_value: false,
@@ -114,7 +85,28 @@ impl From<Option<String>> for ffi::OptionalString {
     }
 }
 
-impl From<Option<bool>> for ffi::OptionalBool {
+impl From<Option<od::UserMetadata<'_>>> for metadata_ffi::OptionalUserMetadata 
{
+    fn from(user_metadata: Option<od::UserMetadata<'_>>) -> Self {
+        match user_metadata {
+            Some(user_metadata) => Self {
+                has_value: true,
+                value: user_metadata
+                    .into_iter()
+                    .map(|(key, value)| metadata_ffi::HashMapValue {
+                        key: key.to_owned(),
+                        value: value.to_owned(),
+                    })
+                    .collect(),
+            },
+            None => Self {
+                has_value: false,
+                value: Vec::new(),
+            },
+        }
+    }
+}
+
+impl From<Option<bool>> for metadata_ffi::OptionalBool {
     fn from(b: Option<bool>) -> Self {
         match b {
             Some(b) => Self {
@@ -150,10 +142,10 @@ impl From<Option<od::Entry>> for ffi::OptionalEntry {
 mod tests {
     use super::*;
 
-    fn last_modified_of(timestamp: od::raw::Timestamp) -> 
ffi::OptionalTimestamp {
+    fn last_modified_of(timestamp: od::raw::Timestamp) -> 
metadata_ffi::OptionalTimestamp {
         let mut builder = od::MetadataBuilder::file(0);
         builder.last_modified(timestamp);
-        let metadata: ffi::Metadata = builder.build().into();
+        let metadata: metadata_ffi::Metadata = builder.build().into();
         metadata.last_modified
     }
 
@@ -184,8 +176,68 @@ mod tests {
 
     #[test]
     fn test_last_modified_absent() {
-        let metadata: ffi::Metadata = 
od::MetadataBuilder::file(0).build().into();
+        let metadata: metadata_ffi::Metadata = 
od::MetadataBuilder::file(0).build().into();
 
         assert!(!metadata.last_modified.has_value);
     }
+
+    #[test]
+    fn test_metadata_carries_every_accessor() {
+        let mut builder = od::MetadataBuilder::file(42);
+        builder
+            .is_current(Some(false))
+            .is_deleted(true)
+            .cache_control("cache_control")
+            .content_md5("content_md5")
+            .content_type("content_type")
+            .content_encoding("content_encoding")
+            .content_language("content_language")
+            .last_modified(od::raw::Timestamp::new(7, 8).unwrap())
+            .etag("etag")
+            .content_disposition("content_disposition")
+            .version("version")
+            .user_metadata([("owner".to_string(), "opendal".to_string())]);
+
+        let metadata: metadata_ffi::Metadata = builder.build().into();
+
+        assert!(metadata.mode == metadata_ffi::EntryMode::File);
+        assert!(metadata.is_current.has_value);
+        assert!(!metadata.is_current.value);
+        assert!(metadata.is_deleted);
+        assert_eq!(metadata.content_length, 42);
+        for (field, expected) in [
+            (&metadata.cache_control, "cache_control"),
+            (&metadata.content_md5, "content_md5"),
+            (&metadata.content_type, "content_type"),
+            (&metadata.content_encoding, "content_encoding"),
+            (&metadata.content_language, "content_language"),
+            (&metadata.etag, "etag"),
+            (&metadata.content_disposition, "content_disposition"),
+            (&metadata.version, "version"),
+        ] {
+            assert!(field.has_value, "{expected} is missing");
+            assert_eq!(field.value, expected);
+        }
+        assert!(metadata.last_modified.has_value);
+        assert_eq!(metadata.last_modified.seconds, 7);
+        assert_eq!(metadata.last_modified.nanoseconds, 8);
+        assert!(metadata.user_metadata.has_value);
+        let pairs: Vec<_> = metadata
+            .user_metadata
+            .value
+            .iter()
+            .map(|pair| (pair.key.as_str(), pair.value.as_str()))
+            .collect();
+        assert_eq!(pairs, [("owner", "opendal")]);
+    }
+
+    #[test]
+    fn test_metadata_keeps_absent_accessors_absent() {
+        let metadata: metadata_ffi::Metadata = 
od::MetadataBuilder::dir().build().into();
+
+        assert!(metadata.mode == metadata_ffi::EntryMode::Dir);
+        assert!(!metadata.is_current.has_value);
+        assert!(!metadata.content_language.has_value);
+        assert!(!metadata.user_metadata.has_value);
+    }
 }
diff --git a/bindings/cpp/src/utils/metadata_converter.cpp 
b/bindings/cpp/src/utils/metadata_converter.cpp
new file mode 100644
index 0000000000..e669c7154e
--- /dev/null
+++ b/bindings/cpp/src/utils/metadata_converter.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+// DO NOT EDIT IT MANUALLY. This file is generated by
+// opendal/dev/src/generate/cpp.rs.
+
+#include "utils/metadata_converter.hpp"
+
+#include <chrono>
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+namespace opendal::utils {
+
+namespace {
+
+std::optional<bool> parse_optional(const ffi::metadata::OptionalBool &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+  return value.value;
+}
+
+std::optional<std::string> parse_optional(
+    const ffi::metadata::OptionalString &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+  return std::string(value.value);
+}
+
+std::optional<std::chrono::system_clock::time_point> parse_optional(
+    const ffi::metadata::OptionalTimestamp &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+
+  auto duration = std::chrono::seconds(value.seconds) +
+                  std::chrono::nanoseconds(value.nanoseconds);
+  return std::chrono::system_clock::time_point(
+      std::chrono::duration_cast<std::chrono::system_clock::duration>(
+          duration));
+}
+
+std::optional<std::unordered_map<std::string, std::string>> parse_optional(
+    const ffi::metadata::OptionalUserMetadata &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+
+  std::unordered_map<std::string, std::string> user_metadata;
+  user_metadata.reserve(value.value.size());
+  for (const auto &entry : value.value) {
+    user_metadata.emplace(std::string(entry.key), std::string(entry.value));
+  }
+  return user_metadata;
+}
+
+}  // namespace
+
+Metadata parse_metadata(const ffi::metadata::Metadata &meta) {
+  Metadata metadata;
+  metadata.type = static_cast<EntryMode>(meta.mode);
+  metadata.is_current = parse_optional(meta.is_current);
+  metadata.is_deleted = meta.is_deleted;
+  metadata.cache_control = parse_optional(meta.cache_control);
+  metadata.content_length = meta.content_length;
+  metadata.content_md5 = parse_optional(meta.content_md5);
+  metadata.content_type = parse_optional(meta.content_type);
+  metadata.content_encoding = parse_optional(meta.content_encoding);
+  metadata.content_language = parse_optional(meta.content_language);
+  metadata.last_modified = parse_optional(meta.last_modified);
+  metadata.etag = parse_optional(meta.etag);
+  metadata.content_disposition = parse_optional(meta.content_disposition);
+  metadata.version = parse_optional(meta.version);
+  metadata.user_metadata = parse_optional(meta.user_metadata);
+  return metadata;
+}
+
+}  // namespace opendal::utils
diff --git a/bindings/cpp/src/utils/metadata_converter.hpp 
b/bindings/cpp/src/utils/metadata_converter.hpp
new file mode 100644
index 0000000000..c42848ab9b
--- /dev/null
+++ b/bindings/cpp/src/utils/metadata_converter.hpp
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "metadata.hpp"
+#include "metadata.rs.h"
+
+namespace opendal::utils {
+
+Metadata parse_metadata(const ffi::metadata::Metadata &meta);
+
+}  // namespace opendal::utils
diff --git a/bindings/cpp/tests/metadata_test.cpp 
b/bindings/cpp/tests/metadata_test.cpp
index 494331075a..5de52cbded 100644
--- a/bindings/cpp/tests/metadata_test.cpp
+++ b/bindings/cpp/tests/metadata_test.cpp
@@ -18,11 +18,17 @@
  */
 
 #include <chrono>
+#include <cstdint>
+#include <memory>
+#include <optional>
 #include <string>
+#include <type_traits>
 #include <unordered_map>
 
 #include "gtest/gtest.h"
+#include "lib.rs.h"
 #include "opendal.hpp"
+#include "utils/metadata_converter.hpp"
 
 class MetadataTest : public ::testing::Test {
  protected:
@@ -611,4 +617,180 @@ TEST_F(MetadataTest, AfterFileModification) {
             modified_metadata.ContentLength());
   EXPECT_GT(modified_metadata.ContentLength(),
             initial_metadata.ContentLength());
-}
\ No newline at end of file
+}
+
+TEST_F(MetadataTest, WrittenFieldsRoundTrip) {
+  opendal::WriteOptions options;
+  options.cache_control = "no-cache";
+  options.content_type = "text/plain";
+  options.content_disposition = "inline";
+  options.content_encoding = "identity";
+  options.user_metadata =
+      std::unordered_map<std::string, std::string>{{"owner", "opendal"}};
+  op.Write("written_fields.txt", "content", options);
+
+  auto metadata = when_i_get_metadata_for("written_fields.txt");
+
+  EXPECT_EQ(metadata.CacheControl(), "no-cache");
+  EXPECT_EQ(metadata.ContentType(), "text/plain");
+  EXPECT_EQ(metadata.ContentDisposition(), "inline");
+  EXPECT_EQ(metadata.ContentEncoding(), "identity");
+  const std::unordered_map<std::string, std::string> expected{
+      {"owner", "opendal"}};
+  EXPECT_EQ(metadata.UserMetadata(), expected);
+  EXPECT_EQ(metadata.user_metadata, expected);
+  EXPECT_EQ(metadata.ContentLanguage(), std::nullopt);
+}
+
+TEST_F(MetadataTest, ContentLanguageCrossesBridge) {
+  // C++ WriteOptions cannot set Content-Language, so a testing hook writes it
+  // from Rust. Operator::Stat converts its result with utils::parse_metadata.
+  const std::unique_ptr<opendal::ffi::Operator,
+                        decltype(&opendal::ffi::delete_operator)>
+      language_op(opendal::ffi::new_test_content_language_operator(
+                      "language.txt", "en-US"),
+                  &opendal::ffi::delete_operator);
+
+  const auto metadata =
+      opendal::utils::parse_metadata(language_op->stat("language.txt"));
+
+  EXPECT_EQ(metadata.ContentLanguage(), "en-US");
+  EXPECT_EQ(metadata.content_language, "en-US");
+}
+
+namespace {
+
+// The `opendal::Metadata` API as declared in `data_structure.hpp` before the
+// class was generated. Existing callers rely on these exact types.
+using opendal::EntryMode;
+using opendal::Metadata;
+using OptionalString = std::optional<std::string>;
+using OptionalTime = std::optional<std::chrono::system_clock::time_point>;
+
+static_assert(std::is_same_v<std::underlying_type_t<EntryMode>, int>);
+static_assert(static_cast<int>(EntryMode::FILE) == 1);
+static_assert(static_cast<int>(EntryMode::DIR) == 2);
+static_assert(static_cast<int>(EntryMode::UNKNOWN) == 0);
+
+static_assert(std::is_same_v<decltype(Metadata::type), EntryMode>);
+static_assert(
+    std::is_same_v<decltype(Metadata::content_length), std::uint64_t>);
+static_assert(
+    std::is_same_v<decltype(Metadata::cache_control), OptionalString>);
+static_assert(
+    std::is_same_v<decltype(Metadata::content_disposition), OptionalString>);
+static_assert(std::is_same_v<decltype(Metadata::content_md5), OptionalString>);
+static_assert(std::is_same_v<decltype(Metadata::content_type), 
OptionalString>);
+static_assert(
+    std::is_same_v<decltype(Metadata::content_encoding), OptionalString>);
+static_assert(std::is_same_v<decltype(Metadata::etag), OptionalString>);
+static_assert(std::is_same_v<decltype(Metadata::last_modified), OptionalTime>);
+static_assert(std::is_same_v<decltype(Metadata::version), OptionalString>);
+static_assert(
+    std::is_same_v<decltype(Metadata::is_current), std::optional<bool>>);
+static_assert(std::is_same_v<decltype(Metadata::is_deleted), bool>);
+
+static_assert(
+    std::is_same_v<decltype(&Metadata::Mode), EntryMode (Metadata::*)() 
const>);
+static_assert(
+    std::is_same_v<decltype(&Metadata::IsFile), bool (Metadata::*)() const>);
+static_assert(
+    std::is_same_v<decltype(&Metadata::IsDir), bool (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::ContentLength),
+                             std::uint64_t (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::CacheControl),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::ContentDisposition),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::ContentMd5),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::ContentType),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::ContentEncoding),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::Etag),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::LastModified),
+                             const OptionalTime& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::Version),
+                             const OptionalString& (Metadata::*)() const>);
+static_assert(std::is_same_v<decltype(&Metadata::IsCurrent),
+                             const std::optional<bool>& (Metadata::*)() 
const>);
+static_assert(
+    std::is_same_v<decltype(&Metadata::IsDeleted), bool (Metadata::*)() 
const>);
+
+// `Metadata() = default;` keeps the class an aggregate only before C++20, so
+// C++17 callers may brace-initialize it by position.
+#if __cplusplus < 202002L
+TEST(MetadataCompatibilityTest, PositionalInitializerKeepsFrozenOrder) {
+  const auto modified =
+      std::chrono::system_clock::time_point(std::chrono::seconds(7));
+  // `type` through `is_deleted` in their order before the class was
+  // generated, then the members appended since.
+  const Metadata metadata{
+      EntryMode::DIR,
+      42,
+      "cache_control",
+      "content_disposition",
+      "content_md5",
+      "content_type",
+      "content_encoding",
+      "etag",
+      modified,
+      "version",
+      false,
+      true,
+      "content_language",
+      std::unordered_map<std::string, std::string>{{"owner", "opendal"}},
+  };
+
+  EXPECT_EQ(metadata.type, EntryMode::DIR);
+  EXPECT_EQ(metadata.content_length, 42u);
+  EXPECT_EQ(metadata.cache_control, "cache_control");
+  EXPECT_EQ(metadata.content_disposition, "content_disposition");
+  EXPECT_EQ(metadata.content_md5, "content_md5");
+  EXPECT_EQ(metadata.content_type, "content_type");
+  EXPECT_EQ(metadata.content_encoding, "content_encoding");
+  EXPECT_EQ(metadata.etag, "etag");
+  EXPECT_EQ(metadata.last_modified, modified);
+  EXPECT_EQ(metadata.version, "version");
+  EXPECT_EQ(metadata.is_current, false);
+  EXPECT_TRUE(metadata.is_deleted);
+  EXPECT_EQ(metadata.content_language, "content_language");
+  const std::unordered_map<std::string, std::string> expected{
+      {"owner", "opendal"}};
+  EXPECT_EQ(metadata.user_metadata, expected);
+}
+
+// The members appended since have default member initializers, so existing
+// initializers of `type` through `is_deleted` stay complete for callers that
+// build with `-Werror=missing-field-initializers`.
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wmissing-field-initializers"
+#endif
+TEST(MetadataCompatibilityTest, HandWrittenPositionalInitializerIsComplete) {
+  const Metadata metadata{
+      EntryMode::FILE,
+      1,
+      "cache_control",
+      "content_disposition",
+      "content_md5",
+      "content_type",
+      "content_encoding",
+      "etag",
+      std::chrono::system_clock::time_point(std::chrono::seconds(1)),
+      "version",
+      true,
+      false,
+  };
+
+  EXPECT_EQ(metadata.content_language, std::nullopt);
+  EXPECT_EQ(metadata.user_metadata, std::nullopt);
+}
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+#endif
+
+}  // namespace
diff --git a/bindings/cpp/upgrade.md b/bindings/cpp/upgrade.md
index 14bc5f795b..302630c497 100644
--- a/bindings/cpp/upgrade.md
+++ b/bindings/cpp/upgrade.md
@@ -19,3 +19,32 @@ from 56 to 152 bytes.
 Rebuild every C++ object that includes OpenDAL headers against the headers and
 library from the same OpenDAL source version. Mixing objects compiled against
 the old headers with the new library is unsupported.
+
+## `opendal::Metadata` gains `content_language` and `user_metadata`
+
+`opendal::Metadata` is now generated from core and gains `content_language`
+(`ContentLanguage()`) and `user_metadata` (`UserMetadata()`, a
+`std::optional<std::unordered_map<std::string, std::string>>`). Core's
+`checksum` is not exposed yet.
+
+The 12 members that existed before (`type` through `is_deleted`) keep their
+names, types, default values, and declaration order, so a C++17 positional
+initializer such as `opendal::Metadata meta{opendal::EntryMode::FILE, 42};`
+keeps its meaning. New members are appended after `is_deleted` and default to
+`std::nullopt`, so a positional initializer of all 12 existing members still
+compiles cleanly with `-Wextra -Werror`.
+
+A structured binding decomposes `opendal::Metadata` into all of its members, so
+a binding with 12 names, such as `const auto& [m1, m2, ..., m12] = metadata;`,
+no longer compiles in C++17 or C++20.
+
+The object layout changed. `sizeof(opendal::Metadata)` grew from 320 to 424
+bytes on Linux x86-64 with GCC 13, and from 264 to 344 bytes on macOS arm64
+with Apple clang. The offsets of the existing members did not change.
+
+**Migration:**
+
+Rebuild every C++ object that includes OpenDAL headers against the headers and
+library from the same OpenDAL source version. Replace a structured binding of
+`opendal::Metadata` with reads of the members you need by name or through
+their accessors, or add two names for `content_language` and `user_metadata`.
diff --git a/dev/src/generate/cpp.rs b/dev/src/generate/cpp.rs
index a11ed8ff5d..302e62187f 100644
--- a/dev/src/generate/cpp.rs
+++ b/dev/src/generate/cpp.rs
@@ -20,8 +20,11 @@
 //! Capability crosses three layers in C++: the cxx shared struct, the Rust
 //! conversion from core, and the public `opendal::Capability` class plus the
 //! copy between them. All three are rendered from the same field list.
+//! `opendal::Metadata` crosses the same three layers and is rendered from the
+//! core accessor list.
 
 use super::capability;
+use super::metadata::{self, MetadataKind};
 use anyhow::{Context, Result, bail};
 use minijinja::value::Serde;
 use minijinja::{Environment, context};
@@ -179,33 +182,35 @@ const FROZEN_PUBLIC_ORDER: &[&str] = &[
 ];
 
 pub fn generate(workspace_dir: &Path) -> Result<()> {
-    generate_capability(workspace_dir)
+    generate_capability(workspace_dir)?;
+    generate_metadata(workspace_dir)
 }
 
-/// Order core fields for the public C++ class by `FROZEN_PUBLIC_ORDER`.
+/// Order core names for a public C++ class by its append-only `frozen` list,
+/// named `list` in errors.
 ///
-/// Fails if a core field is not listed, so a new field cannot take an
+/// Fails if a core name is not listed, so a new member cannot take an
 /// unreviewed position, and if a listed member no longer exists in core,
 /// because dropping it would silently break source compatibility.
-fn public_order<T>(fields: &[T], name_of: impl Fn(&T) -> &str) -> 
Result<Vec<usize>> {
-    if let Some(field) = fields
-        .iter()
-        .find(|f| !FROZEN_PUBLIC_ORDER.contains(&name_of(f)))
-    {
+fn public_order<T>(
+    frozen: &[&str],
+    list: &str,
+    fields: &[T],
+    name_of: impl Fn(&T) -> &str,
+) -> Result<Vec<usize>> {
+    if let Some(field) = fields.iter().find(|f| !frozen.contains(&name_of(f))) 
{
         bail!(
-            "new core capability `{}` must be appended to FROZEN_PUBLIC_ORDER 
in dev/src/generate/cpp.rs",
+            "new core member `{}` must be appended to {list} in 
dev/src/generate/cpp.rs",
             name_of(field)
         );
     }
-    FROZEN_PUBLIC_ORDER
+    frozen
         .iter()
-        .map(|frozen| {
+        .map(|member| {
             fields
                 .iter()
-                .position(|f| name_of(f) == *frozen)
-                .with_context(|| {
-                    format!("frozen C++ capability member `{frozen}` is 
missing from core")
-                })
+                .position(|f| name_of(f) == *member)
+                .with_context(|| format!("{list} member `{member}` is missing 
from core"))
         })
         .collect()
 }
@@ -232,7 +237,10 @@ fn render_capability(workspace_dir: &Path) -> 
Result<Vec<(&'static str, String)>
             doc: f.doc,
         })
         .collect();
-    let public_fields: Vec<&CapabilityField> = public_order(&fields, |f| 
f.name.as_str())?
+    let public_fields: Vec<&CapabilityField> =
+        public_order(FROZEN_PUBLIC_ORDER, "FROZEN_PUBLIC_ORDER", &fields, |f| {
+            f.name.as_str()
+        })?
         .into_iter()
         .map(|i| &fields[i])
         .collect();
@@ -271,6 +279,236 @@ fn cpp_name(name: &str) -> String {
     }
 }
 
+/// Core accessor names of the public `opendal::Metadata` members, in their
+/// released declaration order.
+///
+/// Before C++20 the public class is an aggregate, so callers may
+/// brace-initialize it by position. This order is append-only: generation
+/// fails until every core accessor is listed, so append each new core accessor
+/// to the end of this list.
+const METADATA_FROZEN_PUBLIC_ORDER: &[&str] = &[
+    "mode",
+    "content_length",
+    "cache_control",
+    "content_disposition",
+    "content_md5",
+    "content_type",
+    "content_encoding",
+    "etag",
+    "last_modified",
+    "version",
+    "is_current",
+    "is_deleted",
+    "content_language",
+    "user_metadata",
+];
+
+/// Number of leading `METADATA_FROZEN_PUBLIC_ORDER` members that the
+/// hand-written class declared. Every later member gets a default member
+/// initializer, so a positional initializer of the hand-written members alone
+/// stays complete under `-Wmissing-field-initializers`.
+const METADATA_HAND_WRITTEN_MEMBERS: usize = 12;
+
+/// Render model handed to the C++ metadata templates. Every per-kind decision
+/// is made in `metadata_field`, so the templates stay structural.
+#[derive(Serialize)]
+struct MetadataField {
+    /// Accessor name in core `opendal::Metadata`, also the cxx bridge field.
+    name: String,
+    /// Single-line doc text from core.
+    doc: String,
+    /// `doc` wrapped for the header's `///` comments.
+    hpp_doc_lines: Vec<String>,
+    /// Field type in the cxx bridge struct.
+    bridge_type: &'static str,
+    /// Expression converting the core accessor into the bridge field.
+    rust_value: String,
+    /// Declaration of the public C++ member.
+    hpp_member: String,
+    /// Doc comment and definition of the public C++ accessor, laid out as
+    /// clang-format does.
+    hpp_accessor: String,
+    /// Statement copying the bridge field into the public C++ member.
+    cpp_copy: String,
+}
+
+/// Map one core accessor to its bridge field, conversions, and public C++
+/// member and accessor.
+///
+/// A new return type in core fails parsing in `metadata::parse`, and a new
+/// `MetadataKind` fails this exhaustive match, so an unsupported accessor
+/// cannot be rendered silently.
+fn metadata_field(f: metadata::MetadataField) -> MetadataField {
+    let name = f.name;
+    let mut doc = f.doc;
+    // The binding has always exposed `mode` as the `type` member.
+    let member = if name == "mode" {
+        "type".to_string()
+    } else {
+        name.clone()
+    };
+    let plain = format!("meta.{name}()");
+    let into = format!("meta.{name}().into()");
+    let copy = format!("metadata.{member} = meta.{name};");
+    let parse = format!("metadata.{member} = parse_optional(meta.{name});");
+    // (bridge type, public type, member initializer, returned by reference,
+    // Rust conversion, C++ copy)
+    let (bridge_type, cpp_type, cpp_init, by_ref, rust_value, cpp_copy) = 
match f.kind {
+        MetadataKind::Mode => (
+            "EntryMode",
+            "EntryMode",
+            "{EntryMode::UNKNOWN}",
+            false,
+            into,
+            format!("metadata.{member} = 
static_cast<EntryMode>(meta.{name});"),
+        ),
+        MetadataKind::Bool => ("bool", "bool", "{false}", false, plain, copy),
+        MetadataKind::U64 => ("u64", "std::uint64_t", "{0}", false, plain, 
copy),
+        MetadataKind::OptionBool => ("OptionalBool", "std::optional<bool>", 
"", true, into, parse),
+        MetadataKind::OptionStr => (
+            "OptionalString",
+            "std::optional<std::string>",
+            "",
+            true,
+            into,
+            parse,
+        ),
+        MetadataKind::OptionTimestamp => (
+            "OptionalTimestamp",
+            "std::optional<std::chrono::system_clock::time_point>",
+            "",
+            true,
+            into,
+            parse,
+        ),
+        MetadataKind::OptionUserMetadata => {
+            // Core returns a borrowed view, while C++ receives an owned copy,
+            // so the core doc would be misleading here.
+            doc = format!("Return this entry's {}.", name.replace('_', " "));
+            (
+                "OptionalUserMetadata",
+                "std::optional<std::unordered_map<std::string, std::string>>",
+                "",
+                true,
+                into,
+                parse,
+            )
+        }
+    };
+    let hand_written =
+        
METADATA_FROZEN_PUBLIC_ORDER[..METADATA_HAND_WRITTEN_MEMBERS].contains(&name.as_str());
+    let cpp_init = if cpp_init.is_empty() && !hand_written {
+        "{}"
+    } else {
+        cpp_init
+    };
+    let accessor_type = if by_ref {
+        format!("const {cpp_type}&")
+    } else {
+        cpp_type.to_string()
+    };
+    let hpp_doc_lines = wrap_doc(&doc, HPP_DOC_PREFIX, HPP_COLUMN_LIMIT);
+    let hpp_accessor = hpp_doc_lines
+        .iter()
+        .map(|line| format!("{HPP_DOC_PREFIX}{line}"))
+        .chain(accessor_lines(&accessor_type, &to_pascal(&name), &member))
+        .collect::<Vec<_>>()
+        .join("\n");
+    MetadataField {
+        hpp_member: format!("{cpp_type} {member}{cpp_init};"),
+        hpp_accessor,
+        hpp_doc_lines,
+        doc,
+        bridge_type,
+        rust_value,
+        cpp_copy,
+        name,
+    }
+}
+
+/// Lay out an inline accessor the way clang-format does for the header's
+/// Google style, so the generated header is format-stable.
+fn accessor_lines(ty: &str, method: &str, member: &str) -> Vec<String> {
+    let one_line = format!("  {ty} {method}() const {{ return {member}; }}");
+    if one_line.len() <= HPP_COLUMN_LIMIT {
+        return vec![one_line];
+    }
+    let opening = format!("  {ty} {method}() const {{");
+    let signature = format!("  {ty} {method}()");
+    let mut lines = if opening.len() <= HPP_COLUMN_LIMIT {
+        vec![opening]
+    } else if signature.len() <= HPP_COLUMN_LIMIT {
+        vec![signature, "      const {".to_string()]
+    } else {
+        vec![format!("  {ty}"), format!("  {method}() const {{")]
+    };
+    lines.push(format!("    return {member};"));
+    lines.push("  }".to_string());
+    lines
+}
+
+fn to_pascal(snake: &str) -> String {
+    snake
+        .split('_')
+        .map(|part| {
+            let mut chars = part.chars();
+            match chars.next() {
+                Some(first) => first.to_ascii_uppercase().to_string() + 
chars.as_str(),
+                None => String::new(),
+            }
+        })
+        .collect()
+}
+
+fn generate_metadata(workspace_dir: &Path) -> Result<()> {
+    for (relative, rendered) in render_metadata(workspace_dir)? {
+        fs::write(workspace_dir.join(relative), format!("{rendered}\n"))?;
+    }
+    Ok(())
+}
+
+/// Render every metadata output as `(path relative to workspace, content)`.
+fn render_metadata(workspace_dir: &Path) -> Result<Vec<(&'static str, 
String)>> {
+    let source = workspace_dir.join("core/core/src/types/metadata.rs");
+    // Core order. The cxx bridge and the Rust conversion use this order; the
+    // converter copies by name, so it does not need to match the public class.
+    let fields: Vec<MetadataField> = metadata::parse(&source)?
+        .into_iter()
+        .map(metadata_field)
+        .collect();
+    let public_fields: Vec<&MetadataField> = public_order(
+        METADATA_FROZEN_PUBLIC_ORDER,
+        "METADATA_FROZEN_PUBLIC_ORDER",
+        &fields,
+        |f| f.name.as_str(),
+    )?
+    .into_iter()
+    .map(|i| &fields[i])
+    .collect();
+
+    let mut env = Environment::new();
+    env.add_template("metadata_rs", include_str!("cpp/metadata_rs.j2"))?;
+    env.add_template("metadata_hpp", include_str!("cpp/metadata_hpp.j2"))?;
+    env.add_template("metadata_cpp", include_str!("cpp/metadata_cpp.j2"))?;
+
+    let outputs = [
+        ("metadata_rs", "bindings/cpp/src/metadata.rs"),
+        ("metadata_hpp", "bindings/cpp/include/metadata.hpp"),
+        (
+            "metadata_cpp",
+            "bindings/cpp/src/utils/metadata_converter.cpp",
+        ),
+    ];
+    let mut rendered = Vec::with_capacity(outputs.len());
+    for (template, relative) in outputs {
+        let content = env.get_template(template)?.render(
+            context! { fields => Serde(&fields), public_fields => 
Serde(&public_fields) },
+        )?;
+        rendered.push((relative, content));
+    }
+    Ok(rendered)
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -334,14 +572,19 @@ mod tests {
     fn test_public_order_rejects_unlisted_core_field() {
         let mut fields = FROZEN_PUBLIC_ORDER.to_vec();
         fields.insert(fields.len() / 2, "new_mid");
-        let err = public_order(&fields, |f| f).unwrap_err().to_string();
+        let err = public_order(FROZEN_PUBLIC_ORDER, "FROZEN_PUBLIC_ORDER", 
&fields, |f| f)
+            .unwrap_err()
+            .to_string();
         assert!(err.contains("`new_mid` must be appended to 
FROZEN_PUBLIC_ORDER"));
     }
 
     #[test]
     fn test_public_order_covers_every_core_field_once() {
         let fields = core_fields();
-        let mut order = public_order(&fields, |f| f.name.as_str()).unwrap();
+        let mut order = public_order(FROZEN_PUBLIC_ORDER, 
"FROZEN_PUBLIC_ORDER", &fields, |f| {
+            f.name.as_str()
+        })
+        .unwrap();
         order.sort_unstable();
         assert_eq!(order, (0..fields.len()).collect::<Vec<_>>());
     }
@@ -349,7 +592,7 @@ mod tests {
     #[test]
     fn test_public_order_rejects_missing_frozen_member() {
         let fields = ["stat", "read"];
-        assert!(public_order(&fields, |f| f).is_err());
+        assert!(public_order(FROZEN_PUBLIC_ORDER, "FROZEN_PUBLIC_ORDER", 
&fields, |f| f).is_err());
     }
 
     #[test]
@@ -364,4 +607,81 @@ mod tests {
         assert_eq!(cpp_name("delete"), "delete_feature");
         assert_eq!(cpp_name("delete_with_version"), "delete_with_version");
     }
+
+    #[test]
+    fn test_metadata_public_order_rejects_unlisted_core_accessor() {
+        let mut fields = METADATA_FROZEN_PUBLIC_ORDER.to_vec();
+        fields.insert(fields.len() / 2, "new_mid");
+        let err = public_order(
+            METADATA_FROZEN_PUBLIC_ORDER,
+            "METADATA_FROZEN_PUBLIC_ORDER",
+            &fields,
+            |f| f,
+        )
+        .unwrap_err()
+        .to_string();
+        assert!(err.contains("`new_mid` must be appended to 
METADATA_FROZEN_PUBLIC_ORDER"));
+    }
+
+    #[test]
+    fn test_metadata_public_order_rejects_missing_frozen_member() {
+        let fields = ["mode", "content_length"];
+        let err = public_order(
+            METADATA_FROZEN_PUBLIC_ORDER,
+            "METADATA_FROZEN_PUBLIC_ORDER",
+            &fields,
+            |f| f,
+        )
+        .unwrap_err()
+        .to_string();
+        assert!(err.contains("`cache_control` is missing from core"));
+    }
+
+    #[test]
+    fn test_accessor_lines_match_clang_format() {
+        // Layouts that clang-format 18 and 23 produce with bindings/cpp's
+        // Google style.
+        assert_eq!(
+            accessor_lines("EntryMode", "Mode", "type"),
+            ["  EntryMode Mode() const { return type; }"]
+        );
+        assert_eq!(
+            accessor_lines(
+                "const std::optional<std::string>&",
+                "ContentDisposition",
+                "content_disposition"
+            ),
+            [
+                "  const std::optional<std::string>& ContentDisposition() 
const {",
+                "    return content_disposition;",
+                "  }",
+            ]
+        );
+        assert_eq!(
+            accessor_lines(
+                "const std::optional<std::chrono::system_clock::time_point>&",
+                "LastModified",
+                "last_modified"
+            ),
+            [
+                "  const std::optional<std::chrono::system_clock::time_point>& 
LastModified()",
+                "      const {",
+                "    return last_modified;",
+                "  }",
+            ]
+        );
+        assert_eq!(
+            accessor_lines(
+                "const std::optional<std::unordered_map<std::string, 
std::string>>&",
+                "UserMetadata",
+                "user_metadata"
+            ),
+            [
+                "  const std::optional<std::unordered_map<std::string, 
std::string>>&",
+                "  UserMetadata() const {",
+                "    return user_metadata;",
+                "  }",
+            ]
+        );
+    }
 }
diff --git a/dev/src/generate/cpp/metadata_cpp.j2 
b/dev/src/generate/cpp/metadata_cpp.j2
new file mode 100644
index 0000000000..c32e145707
--- /dev/null
+++ b/dev/src/generate/cpp/metadata_cpp.j2
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+// DO NOT EDIT IT MANUALLY. This file is generated by
+// opendal/dev/src/generate/cpp.rs.
+
+#include "utils/metadata_converter.hpp"
+
+#include <chrono>
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+namespace opendal::utils {
+
+namespace {
+
+std::optional<bool> parse_optional(const ffi::metadata::OptionalBool &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+  return value.value;
+}
+
+std::optional<std::string> parse_optional(
+    const ffi::metadata::OptionalString &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+  return std::string(value.value);
+}
+
+std::optional<std::chrono::system_clock::time_point> parse_optional(
+    const ffi::metadata::OptionalTimestamp &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+
+  auto duration = std::chrono::seconds(value.seconds) +
+                  std::chrono::nanoseconds(value.nanoseconds);
+  return std::chrono::system_clock::time_point(
+      std::chrono::duration_cast<std::chrono::system_clock::duration>(
+          duration));
+}
+
+std::optional<std::unordered_map<std::string, std::string>> parse_optional(
+    const ffi::metadata::OptionalUserMetadata &value) {
+  if (!value.has_value) {
+    return std::nullopt;
+  }
+
+  std::unordered_map<std::string, std::string> user_metadata;
+  user_metadata.reserve(value.value.size());
+  for (const auto &entry : value.value) {
+    user_metadata.emplace(std::string(entry.key), std::string(entry.value));
+  }
+  return user_metadata;
+}
+
+}  // namespace
+
+Metadata parse_metadata(const ffi::metadata::Metadata &meta) {
+  Metadata metadata;
+{%- for f in fields %}
+  {{ f.cpp_copy }}
+{%- endfor %}
+  return metadata;
+}
+
+}  // namespace opendal::utils
diff --git a/dev/src/generate/cpp/metadata_hpp.j2 
b/dev/src/generate/cpp/metadata_hpp.j2
new file mode 100644
index 0000000000..245b7b9525
--- /dev/null
+++ b/dev/src/generate/cpp/metadata_hpp.j2
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+// DO NOT EDIT IT MANUALLY. This file is generated by
+// opendal/dev/src/generate/cpp.rs.
+
+#pragma once
+
+#include <chrono>
+#include <cstdint>
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+namespace opendal {
+
+/**
+ * @enum EntryMode
+ * @brief The mode of the entry
+ */
+enum class EntryMode : int {
+  FILE = 1,
+  DIR = 2,
+  UNKNOWN = 0,
+};
+
+/**
+ * @struct Metadata
+ * @brief The metadata of a file or directory
+ *
+ * Metadata contains all the information related to a specific path.
+ * Depending on the context of the requests, the metadata for the same path may
+ * vary. For example, two versions of the same path might have different 
content
+ * lengths. Keep in mind that metadata is always tied to the given context and
+ * is not a global state.
+ */
+class Metadata {
+ public:
+{%- for f in public_fields %}
+{%- for line in f.hpp_doc_lines %}
+  /// {{ line }}
+{%- endfor %}
+  {{ f.hpp_member }}
+{%- endfor %}
+
+  Metadata() = default;
+
+  ~Metadata() = default;
+{%- for f in public_fields %}
+
+{{ f.hpp_accessor }}
+{%- if f.name == "mode" %}
+
+  /**
+   * @brief Check if this metadata represents a file
+   * @return true if this is a file, false otherwise
+   */
+  bool IsFile() const { return type == EntryMode::FILE; }
+
+  /**
+   * @brief Check if this metadata represents a directory
+   * @return true if this is a directory, false otherwise
+   */
+  bool IsDir() const { return type == EntryMode::DIR; }
+{%- endif %}
+{%- endfor %}
+};
+
+}  // namespace opendal
diff --git a/dev/src/generate/cpp/metadata_rs.j2 
b/dev/src/generate/cpp/metadata_rs.j2
new file mode 100644
index 0000000000..67d53a2200
--- /dev/null
+++ b/dev/src/generate/cpp/metadata_rs.j2
@@ -0,0 +1,76 @@
+// 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.
+
+// DO NOT EDIT IT MANUALLY. This file is generated by 
opendal/dev/src/generate/cpp.rs.
+
+/// Shared metadata struct, kept in its own bridge so it can be generated from
+/// core and reused by the main bridge in `lib.rs`.
+///
+/// `lib.rs.h` includes this bridge's header, so this bridge cannot use the
+/// value structs of `lib.rs` and declares its own in a nested namespace.
+#[cxx::bridge(namespace = "opendal::ffi::metadata")]
+pub mod ffi {
+    enum EntryMode {
+        File = 1,
+        Dir = 2,
+        Unknown = 0,
+    }
+
+    struct OptionalBool {
+        has_value: bool,
+        value: bool,
+    }
+
+    struct OptionalString {
+        has_value: bool,
+        value: String,
+    }
+
+    struct OptionalTimestamp {
+        has_value: bool,
+        seconds: i64,
+        nanoseconds: u32,
+    }
+
+    struct HashMapValue {
+        key: String,
+        value: String,
+    }
+
+    struct OptionalUserMetadata {
+        has_value: bool,
+        value: Vec<HashMapValue>,
+    }
+
+    /// Metadata of an entry.
+    struct Metadata {
+{%- for f in fields %}
+        /// {{ f.doc }}
+        {{ f.name }}: {{ f.bridge_type }},
+{%- endfor %}
+    }
+}
+
+impl From<opendal::Metadata> for ffi::Metadata {
+    fn from(meta: opendal::Metadata) -> Self {
+        Self {
+{%- for f in fields %}
+            {{ f.name }}: {{ f.rust_value }},
+{%- endfor %}
+        }
+    }
+}

Reply via email to