diff --git a/docs/api.rst b/docs/api.rst index b0a076abf..630ef8fe1 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -55,6 +55,8 @@ Data Structures .. autoctype:: types.h::zp_send_keep_alive_options_t .. autoctype:: types.h::zp_send_join_options_t .. autoctype:: types.h::z_qos_t +.. autoctype:: types.h::z_bytes_iterator_t + Owned Types ~~~~~~~~~~~ @@ -320,6 +322,11 @@ Primitives .. autocfunction:: primitives.h::z_bytes_serialize_from_slice_copy .. autocfunction:: primitives.h::z_bytes_serialize_from_string .. autocfunction:: primitives.h::z_bytes_serialize_from_string_copy +.. autocfunction:: primitives.h::z_bytes_empty +.. autocfunction:: primitives.h::z_bytes_len +.. autocfunction:: primitives.h::z_bytes_is_empty +.. autocfunction:: primitives.h::z_bytes_get_iterator +.. autocfunction:: primitives.h::z_bytes_iterator_next .. autocfunction:: primitives.h::z_timestamp_check .. autocfunction:: primitives.h::z_query_target_default .. autocfunction:: primitives.h::z_query_consolidation_auto diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index a78862a65..938765e6a 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -844,10 +844,30 @@ z_bytes_iterator_t z_bytes_get_iterator(const z_loaned_bytes_t *bytes); * iter: An iterator over multi-element serialized data. * out: An uninitialized :c:type:`z_owned_bytes_t` that will contained next serialized element. * Return: - * ``false`` when iterator reaches the end, ``true`` otherwise + * ``false`` when iterator reaches the end, ``true`` otherwise. */ _Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *out); +/** + * Returns total number of bytes in the container. + * + * Parameters: + * bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode. + * Return: + * Number of bytes in the container. + */ +size_t z_bytes_len(const z_loaned_bytes_t *bytes); + +/** + * Checks if container is empty + * + * Parameters: + * bytes: Pointer to a :c:type:`z_loaned_bytes_t` to decode. + * Return: + * ``true`` if conainer is empty, ``false`` otherwise. + */ +_Bool z_bytes_is_empty(const z_loaned_bytes_t *bytes); + /** * Checks validity of a timestamp * diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index 71e918f59..3899671de 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -76,7 +76,7 @@ _Z_OWNED_TYPE_PTR(_z_bytes_t, bytes) _Z_LOANED_TYPE(_z_bytes_t, bytes) /** - * An iterator over multi-element serialized data + * An iterator over multi-element serialized data. */ typedef _z_bytes_iterator_t z_bytes_iterator_t; diff --git a/src/api/api.c b/src/api/api.c index ccc9d3b4d..1a73df43b 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -472,6 +472,10 @@ int8_t z_bytes_empty(z_owned_bytes_t *bytes) { return _Z_RES_OK; } +size_t z_bytes_len(const z_loaned_bytes_t *bytes) { return _z_bytes_len(bytes); } + +_Bool z_bytes_is_empty(const z_loaned_bytes_t *bytes) { return _z_bytes_is_empty(bytes); } + z_bytes_iterator_t z_bytes_get_iterator(const z_loaned_bytes_t *bytes) { return _z_bytes_get_iterator(bytes); } _Bool z_bytes_iterator_next(z_bytes_iterator_t *iter, z_owned_bytes_t *bytes) {