Skip to content

Commit

Permalink
add z_encoding_equals (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 authored Sep 18, 2024
1 parent 7b04daa commit 98c2283
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 98c2283

Please sign in to comment.