Skip to content

Commit

Permalink
tag z_bytes_get_contiguous_view as unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 18, 2024
1 parent abff312 commit 9fcb738
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,7 @@ z_result_t z_bytes_from_str(struct z_owned_bytes_t *this_,
*/
ZENOHC_API void z_bytes_from_string(struct z_owned_bytes_t *this_, struct z_moved_string_t *s);
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* Attempts to get a contiguous view to the underlying bytes.
* This is only possible if data is not fragmented, otherwise the function will fail.
* In case of fragmented data, consider using `z_bytes_get_slice_iterator()`.
Expand All @@ -1549,9 +1550,11 @@ ZENOHC_API void z_bytes_from_string(struct z_owned_bytes_t *this_, struct z_move
* @param view: An uninitialized memory location where a contiguous view on data will be constructed.
* @return ​0​ upon success, negative error code otherwise.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
z_result_t z_bytes_get_contiguous_view(const struct z_loaned_bytes_t *this_,
struct z_view_slice_t *view);
#endif
/**
* Returns a reader for the data.
*
Expand Down
2 changes: 2 additions & 0 deletions src/zbytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ pub extern "C" fn z_bytes_slice_iterator_next(
}
}

#[cfg(feature = "unstable")]
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// Attempts to get a contiguous view to the underlying bytes.
/// This is only possible if data is not fragmented, otherwise the function will fail.
/// In case of fragmented data, consider using `z_bytes_get_slice_iterator()`.
Expand Down
4 changes: 4 additions & 0 deletions tests/z_api_payload_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ void test_slices(void) {
z_bytes_copy_from_buf(&payload, data, 10);
assert(check_slice(z_loan(payload), data, 10));

#if defined(Z_FEATURE_UNSTABLE_API)
z_view_slice_t view;
assert(z_bytes_get_contiguous_view(z_loan(payload), &view) == Z_OK);
assert(z_slice_len(z_loan(view)) == 10);
assert(memcmp(data, z_slice_data(z_loan(view)), 10) == 0);
#endif

z_drop(z_move(payload));

Expand All @@ -252,7 +254,9 @@ void test_slices(void) {
}
z_bytes_writer_finish(z_move(writer), &payload);
assert(check_slice(z_loan(payload), data, 10));
#if defined(Z_FEATURE_UNSTABLE_API)
assert(z_bytes_get_contiguous_view(z_loan(payload), &view) != Z_OK);
#endif
z_drop(z_move(payload));
}

Expand Down

0 comments on commit 9fcb738

Please sign in to comment.