Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary results #622

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1438,20 +1438,18 @@ z_result_t z_bytes_from_buf(struct z_owned_bytes_t *this_,
* @param this_: An uninitialized location in memory where `z_owned_bytes_t` is to be constructed.
* @param iterator_body: Iterator body function, providing data items. Returning false is treated as iteration end.
* @param context: Arbitrary context that will be passed to iterator_body.
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API
z_result_t z_bytes_from_iter(struct z_owned_bytes_t *this_,
bool (*iterator_body)(struct z_owned_bytes_t *data, void *context),
void *context);
void z_bytes_from_iter(struct z_owned_bytes_t *this_,
bool (*iterator_body)(struct z_owned_bytes_t *data, void *context),
void *context);
/**
* Serializes a pair of `z_owned_bytes_t` objects which are consumed in the process.
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API
z_result_t z_bytes_from_pair(struct z_owned_bytes_t *this_,
struct z_moved_bytes_t *first,
struct z_moved_bytes_t *second);
void z_bytes_from_pair(struct z_owned_bytes_t *this_,
struct z_moved_bytes_t *first,
struct z_moved_bytes_t *second);
/**
* Serializes a slice.
* The slice is consumed upon function return.
Expand Down Expand Up @@ -1657,20 +1655,16 @@ ZENOHC_API void z_bytes_serialize_from_uint8(struct z_owned_bytes_t *this_, uint
* Appends bytes.
* This allows to compose a serialized data out of multiple `z_owned_bytes_t` that may point to different memory regions.
* Said in other terms, it allows to create a linear view on different memory regions without copy.
*
* @return 0 in case of success, negative error code otherwise
*/
ZENOHC_API
z_result_t z_bytes_writer_append(struct z_bytes_writer_t *this_,
struct z_moved_bytes_t *bytes);
void z_bytes_writer_append(struct z_bytes_writer_t *this_,
struct z_moved_bytes_t *bytes);
/**
* Appends bytes, with boundaries information. It would allow to read the same piece of data using `z_bytes_reader_read_bounded()`.
*
* @return 0 in case of success, negative error code otherwise
*/
ZENOHC_API
z_result_t z_bytes_writer_append_bounded(struct z_bytes_writer_t *this_,
struct z_moved_bytes_t *bytes);
void z_bytes_writer_append_bounded(struct z_bytes_writer_t *this_,
struct z_moved_bytes_t *bytes);
/**
* Writes `len` bytes from `src` into underlying data.
*
Expand Down
18 changes: 4 additions & 14 deletions src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,14 @@ pub unsafe extern "C" fn z_bytes_serialize_from_str(
}

/// Serializes a pair of `z_owned_bytes_t` objects which are consumed in the process.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
pub extern "C" fn z_bytes_from_pair(
this: &mut MaybeUninit<z_owned_bytes_t>,
first: &mut z_moved_bytes_t,
second: &mut z_moved_bytes_t,
) -> z_result_t {
) {
let payload = ZBytes::serialize((first.take_rust_type(), second.take_rust_type()));
this.as_rust_type_mut_uninit().write(payload);
Z_OK
}

/// Deserializes into a pair of `z_owned_bytes_t` objects.
Expand Down Expand Up @@ -712,7 +710,6 @@ impl Iterator for ZBytesInIterator {
/// @param this_: An uninitialized location in memory where `z_owned_bytes_t` is to be constructed.
/// @param iterator_body: Iterator body function, providing data items. Returning false is treated as iteration end.
/// @param context: Arbitrary context that will be passed to iterator_body.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
pub extern "C" fn z_bytes_from_iter(
this: &mut MaybeUninit<z_owned_bytes_t>,
Expand All @@ -721,15 +718,14 @@ pub extern "C" fn z_bytes_from_iter(
context: *mut c_void,
) -> bool,
context: *mut c_void,
) -> z_result_t {
) {
let it = ZBytesInIterator {
body: iterator_body,
context,
};

let b = ZBytes::from_iter(it);
this.as_rust_type_mut_uninit().write(b);
Z_OK
}

pub use crate::z_bytes_iterator_t;
Expand Down Expand Up @@ -925,27 +921,21 @@ unsafe extern "C" fn z_bytes_writer_write_all(
/// Appends bytes.
/// This allows to compose a serialized data out of multiple `z_owned_bytes_t` that may point to different memory regions.
/// Said in other terms, it allows to create a linear view on different memory regions without copy.
///
/// @return 0 in case of success, negative error code otherwise
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
unsafe extern "C" fn z_bytes_writer_append(
this: &mut z_bytes_writer_t,
bytes: &mut z_moved_bytes_t,
) -> z_result_t {
) {
this.as_rust_type_mut().append(bytes.take_rust_type());
result::Z_OK
}

/// Appends bytes, with boundaries information. It would allow to read the same piece of data using `z_bytes_reader_read_bounded()`.
///
/// @return 0 in case of success, negative error code otherwise
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
unsafe extern "C" fn z_bytes_writer_append_bounded(
this: &mut z_bytes_writer_t,
bytes: &mut z_moved_bytes_t,
) -> z_result_t {
) {
this.as_rust_type_mut().serialize(bytes.take_rust_type());
result::Z_OK
}
6 changes: 3 additions & 3 deletions tests/z_api_payload_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ void test_bounded(void) {
for (size_t i = 0; i < 10; ++i) {
z_owned_bytes_t b;
z_bytes_serialize_from_uint32(&b, data[i]);
assert(z_bytes_writer_append_bounded(&writer, z_move(b)) == 0);
z_bytes_writer_append_bounded(&writer, z_move(b));
}
{
z_owned_bytes_t b;
z_bytes_serialize_from_str(&b, "test");
assert(z_bytes_writer_append_bounded(&writer, z_move(b)) == 0);
z_bytes_writer_append_bounded(&writer, z_move(b));
}

z_bytes_reader_t reader = z_bytes_get_reader(z_loan(payload));
Expand Down Expand Up @@ -154,7 +154,7 @@ void test_append(void) {
{
z_owned_bytes_t b;
z_bytes_serialize_from_buf(&b, data + 5, 5);
assert(z_bytes_writer_append(&writer, z_move(b)) == 0);
z_bytes_writer_append(&writer, z_move(b));
}

z_bytes_reader_t reader = z_bytes_get_reader(z_loan(payload));
Expand Down