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 z_view_slice_from_buf method #694

Merged
merged 1 commit into from
Sep 27, 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
13 changes: 13 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,19 @@ z_result_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, si
z_result_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len,
void (*deleter)(void *data, void *context), void *context);

/**
* Builds a :c:type:`z_view_slice_t`.
*
* Parameters:
* slice: Pointer to an uninitialized :c:type:`z_view_slice_t`.
* data: Pointer to the data to be pointed by `slice`.
* len: Number of bytes in `data`.
*
* Return:
* ``0`` if creation successful, ``negative value`` otherwise.
*/
z_result_t z_view_slice_from_buf(z_view_slice_t *slice, uint8_t *data, size_t len);

/**
* Builds an empty :c:type:`z_owned_slice_t`.
*
Expand Down
5 changes: 5 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ z_result_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len,
return _Z_RES_OK;
}

z_result_t z_view_slice_from_buf(z_view_slice_t *slice, uint8_t *data, size_t len) {
slice->_val = _z_slice_alias_buf(data, len);
return _Z_RES_OK;
}

const uint8_t *z_slice_data(const z_loaned_slice_t *slice) { return slice->start; }

size_t z_slice_len(const z_loaned_slice_t *slice) { return slice->len; }
Expand Down
Loading