diff --git a/docs/api.rst b/docs/api.rst index 15eb15c5e..e957b8dd3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -386,6 +386,7 @@ Primitives .. autocfunction:: primitives.h::z_string_copy_from_substr .. autocfunction:: primitives.h::z_string_empty .. autocfunction:: primitives.h::z_string_is_empty +.. autocfunction:: primitives.h::z_string_as_slice .. autocfunction:: primitives.h::z_hello_zid .. autocfunction:: primitives.h::z_hello_whatami .. autocfunction:: primitives.h::z_hello_locators diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index b02655ac9..710c408b1 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1432,6 +1432,16 @@ int8_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_ */ bool z_string_is_empty(const z_loaned_string_t *str); +/** + * Returns :c:type:`z_loaned_slice_t` for the string + * + * Parameters: + * str: Pointer to a :c:type:`z_loaned_string_t` to get slice. + * Return: + * slice containing string data + */ +const z_loaned_slice_t *z_string_as_slice(const z_loaned_string_t *str); + /** * Returns id of Zenoh entity that transmitted hello message. * diff --git a/src/api/api.c b/src/api/api.c index 34f142d4f..10959ccfc 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1031,6 +1031,8 @@ int8_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_ bool z_string_is_empty(const z_loaned_string_t *str) { return _z_string_is_empty(str); } +const z_loaned_slice_t *z_string_as_slice(const z_loaned_string_t *str) { return &str->_slice; } + #if Z_FEATURE_PUBLICATION == 1 int8_t _z_undeclare_and_clear_publisher(_z_publisher_t *pub) { int8_t ret = _Z_RES_OK;