Ji-Xinyou commented on code in PR #1892:
URL:
https://github.com/apache/incubator-opendal/pull/1892#discussion_r1161833048
##########
bindings/c/include/opendal.h:
##########
@@ -194,15 +205,57 @@ enum opendal_code
opendal_operator_blocking_write(opendal_operator_ptr op_ptr,
It is [safe] under two cases below
* The memory pointed to by `path` must contain a valid nul terminator at the
end of
the string.
- * The `path` points to NULL, this function simply returns you a nullptr
+ * The `path` points to NULL, this function simply returns you a nullptr for
`data`
+ and corresponding error code.
*/
struct opendal_result_read opendal_operator_blocking_read(opendal_operator_ptr
op_ptr,
const char *path);
+/*
+ Check whether the path exists.
+
+ If the operation succeeds, no matter the path exists or not,
+ the error code should be opendal_code::OPENDAL_OK. Otherwise,
+ the field `exist` is filled with false, and the error code
+ is set correspondingly.
+
+ # Safety
+
+ It is [safe] under two cases below
+ * The memory pointed to by `path` must contain a valid nul terminator at the
end of
+ the string.
+ * The `path` points to NULL, this function simply returns you a false for
field `exist`
+ and corresponding error code.
+ */
+struct opendal_result_exist opendal_operator_is_exist(opendal_operator_ptr
op_ptr,
+ const char *path);
+
+/*
+ Creates a new [`opendal_bytes`] from the raw pointer to the actual data and
its length.
+
+ The length and the data have to be consistent. If a longer len is provided,
invalid memory
+ access might happen. If a short len is provided, the data gets truncated.
+ */
+struct opendal_bytes opendal_bytes_new(uint8_t *bytes, uintptr_t len);
+
/*
Frees the heap memory used by the [`opendal_bytes`]
+
+ # Safety
+
+ Please make sure that the pointer is non-null and pointing at a valid [`Vec`].
+ */
+void opendal_bytes_free(const struct opendal_bytes *self);
+
+/*
+ Get the length of the data contained by `bytes`
+ */
+uintptr_t opendal_bytes_len_get(const struct opendal_bytes *self);
Review Comment:
The question is roughly the same as
https://github.com/apache/incubator-opendal/pull/1892#discussion_r1161789633.
In C, array is simply just a pointer, pointing the zero-th entry of the data.
Therefore, the main difference between `Vec` and C array would be
1. The `Vec's` data is allocated on heap for sure, but C array probably is
on stack.
2. The `Vec` knows the `length` of the data, but C array does not.
Hence if a plain `uint8_t*` is returned, the caller will not know where this
array ends, this could be solved by a simple `len` field. The minimal way of
playing bytes in C would be a pointer to the zero-th entry and a variable
recording the length.
--
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]