Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyexpr_was_declared api function #315

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,23 @@ z_owned_str_t z_keyexpr_to_string(z_keyexpr_t keyexpr);
*
* Returns:
* The :c:type:`z_bytes_t` pointing to key expression string representation if it's possible

*/
z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr);

/**
* Indicates if the key expression has been declared but don't guarantee it's still in session.
Copy link
Contributor

@milyin milyin Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add that it's not possible to get key expression string representation if it's declared and add a reference to zp_resolve as a way to access this data. This will make clear why this function is needed and connect this function to two functions above

*
* If given keyexpr was declared, to retrieve the keyexpr string representation the user must use
* :c:func:zp_keyexpr_resolve
*
* Parameters:
* keyexpr: A loaned instance of :c:type:`z_keyexpr_t`
*
* Returns:
* Returns ``true`` if the keyexpr was declared or ``false`` otherwise.
*/
_Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr);

/**
* Constructs a null-terminated string departing from a :c:type:`z_keyexpr_t` for a given :c:type:`z_session_t`.
* The user is responsible of dropping the returned string using ``z_free``.
Expand Down
8 changes: 8 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
}
}

_Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
_Bool ret = false;
if (keyexpr->_id != Z_RESOURCE_ID_NONE) {
ret = true;
}
return ret;
}

z_owned_str_t zp_keyexpr_resolve(z_session_t zs, z_keyexpr_t keyexpr) {
z_owned_str_t ret = {._value = NULL};

Expand Down
Loading