From 98c2283b41bd958d85f07a3f2bb375ee3977bed5 Mon Sep 17 00:00:00 2001 From: DenisBiryukov91 <155981813+DenisBiryukov91@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:29:41 +0200 Subject: [PATCH] add z_encoding_equals (#682) --- docs/api.rst | 1 + include/zenoh-pico/api/primitives.h | 12 ++++++++++++ src/api/api.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index b78f52968..1d9b5a097 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -311,6 +311,7 @@ Primitives .. autocfunction:: primitives.h::z_encoding_set_schema_from_str .. autocfunction:: primitives.h::z_encoding_set_schema_from_substr .. autocfunction:: primitives.h::z_encoding_to_string +.. autocfunction:: primitives.h::z_encoding_equals .. autocfunction:: primitives.h::z_reply_err_payload .. autocfunction:: primitives.h::z_reply_err_encoding .. autocfunction:: primitives.h::z_slice_from_buf diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 37edbaba2..1ec569a1a 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -387,6 +387,18 @@ z_result_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, cons */ z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *string); +/** + * Checks if 2 encodings are equal. + * + * Parameters: + * left: Pointer to first :c:type:`z_loaned_encoding_t` to compare. + * right: Pointer to second :c:type:`z_loaned_encoding_t` to compare. + * + * Return: + * ``true`` if `left` equals `right`, ``false`` otherwise. + */ +bool z_encoding_equals(const z_loaned_encoding_t *left, const z_loaned_encoding_t *right); + /** * Gets the bytes data from a reply error payload by aliasing it. * diff --git a/src/api/api.c b/src/api/api.c index d20ac38b2..b693bf53f 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -406,6 +406,10 @@ z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_str return _Z_RES_OK; } +bool z_encoding_equals(const z_loaned_encoding_t *left, const z_loaned_encoding_t *right) { + return left->id == right->id && _z_string_equals(&left->schema, &right->schema); +} + z_result_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len) { slice->_val = _z_slice_copy_from_buf(data, len); if (slice->_val.start == NULL) {