Skip to content

Commit

Permalink
add z_encoding_equals (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 authored Sep 18, 2024
1 parent ef82239 commit 7fb6cb9
Show file tree
Hide file tree
Showing 4 changed files with 25 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 @@ -225,6 +225,7 @@ Functions
.. doxygenfunction:: z_encoding_set_schema_from_str
.. doxygenfunction:: z_encoding_set_schema_from_substr
.. doxygenfunction:: z_encoding_to_string
.. doxygenfunction:: z_encoding_equals

Predefined Encodings
^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,12 @@ void z_encoding_clone(struct z_owned_encoding_t *dst,
* Frees the memory and resets the encoding it to its default value.
*/
ZENOHC_API void z_encoding_drop(struct z_moved_encoding_t *this_);
/**
* Returns ``true`` if `this_` equals to `other`, ``false`` otherwise.
*/
ZENOHC_API
bool z_encoding_equals(const struct z_loaned_encoding_t *this_,
const struct z_loaned_encoding_t *other);
/**
* Constructs a `z_owned_encoding_t` from a specified string.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ pub extern "C" fn z_encoding_clone(
.write(this.as_rust_type_ref().clone());
}

/// Returns ``true`` if `this_` equals to `other`, ``false`` otherwise.
#[no_mangle]
pub extern "C" fn z_encoding_equals(
this_: &z_loaned_encoding_t,
other: &z_loaned_encoding_t,
) -> bool {
this_.as_rust_type_ref() == other.as_rust_type_ref()
}

/// Just some bytes.
///
/// Constant alias for string: `"zenoh/bytes"`.
Expand Down
9 changes: 9 additions & 0 deletions tests/z_api_encoding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ void test_constants() {
z_string_drop(z_move(s));
}

void test_equals() {
z_owned_encoding_t e;
z_encoding_from_str(&e, "zenoh/string");
assert(z_encoding_equals(z_loan(e), z_encoding_zenoh_string()));
assert(!z_encoding_equals(z_loan(e), z_encoding_zenoh_int16()));
z_drop(z_move(e));
}

int main(int argc, char **argv) {
test_null_encoding();
test_encoding_without_id();
test_encoding_with_id();
test_constants();
test_with_schema();
test_equals();
}

0 comments on commit 7fb6cb9

Please sign in to comment.