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

add Bytes::get_contiguous_view method to allow getting a contiguous view to zenoh::Bytes data in case it is non-fragmented #336

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
19 changes: 19 additions & 0 deletions include/zenoh/api/bytes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ class Bytes : public Owned<::z_owned_bytes_t> {
return s;
}

#if defined(Z_FEATURE_UNSTABLE_API)
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Attempt 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 ``Bytes::slice_iter``.
/// @return A ``Slice`` containing pointer to underlying data and its length if data is non fragmented, an empty
/// value otherwise.
std::optional<Slice> get_contiguous_view() const {
::z_view_slice_t view;
if (::z_bytes_get_contiguous_view(interop::as_loaned_c_ptr(*this), &view) == Z_OK) {
return make_slice(::z_slice_data(z_loan(view)), ::z_slice_len(z_loan(view)));
} else {
return {};
}
}
#endif

#if (defined(Z_FEATURE_SHARED_MEMORY) && defined(Z_FEATURE_UNSTABLE_API))
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
Expand Down
Loading