Skip to content

Commit

Permalink
feat: add z_id_to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Aug 26, 2024
1 parent 7849757 commit 6a93c5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,18 @@ int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *c
*/
z_id_t z_info_zid(const z_loaned_session_t *zs);

/**
* Converts a Zenoh ID into a null-terminated string for print purposes.
*
* Parameters:
* str: Pointer to uninitialized :c:type:`z_owned_string_t` to store the string.
* id: Pointer to the id to convert.
*
* Return:
* ``0`` if operation successful, ``negative value`` otherwise.
*/
z_result_t z_id_to_string(z_owned_string_t *str, z_id_t *id);

/**
* Gets the keyexpr from a sample by aliasing it.
*
Expand Down
9 changes: 9 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,15 @@ int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *c

z_id_t z_info_zid(const z_loaned_session_t *zs) { return _Z_RC_IN_VAL(zs)->_local_zid; }

z_result_t z_id_to_string(z_owned_string_t *str, z_id_t *id) {
_z_slice_t buf = _z_slice_from_buf(id->id, sizeof(id->id));
str->_val = _z_string_convert_bytes(&buf);
if (!_z_string_check(&str->_val)) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
return _Z_RES_OK;
}

const z_loaned_keyexpr_t *z_sample_keyexpr(const z_loaned_sample_t *sample) { return &sample->keyexpr; }
z_sample_kind_t z_sample_kind(const z_loaned_sample_t *sample) { return sample->kind; }
const z_loaned_bytes_t *z_sample_payload(const z_loaned_sample_t *sample) { return &sample->payload; }
Expand Down

0 comments on commit 6a93c5e

Please sign in to comment.