Skip to content

Commit

Permalink
Add z_timestamp_t methods (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc authored Jul 4, 2024
1 parent ab8f8de commit c67de6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,29 @@ void z_bytes_get_writer(z_loaned_bytes_t *bytes, z_owned_bytes_writer_t *writer)
*/
int8_t z_bytes_writer_write(z_loaned_bytes_writer_t *writer, const uint8_t *src, size_t len);

/**
* Create timestamp
*
* Parameters:
* ts: An uninitialized :c:type:`z_timestamp_t`.
* npt64_time: NPT64 time.
* zid: id associated with this timestamp
*
* Return:
* ``0`` if encode successful, ``negative value`` otherwise.
*/
int8_t z_timestamp_new(z_timestamp_t *ts, const z_id_t *zid, uint64_t npt64_time);

/**
* Returns NPT64 time associated with this timestamp.
*/
uint64_t z_timestamp_npt64_time(const z_timestamp_t *ts);

/**
* Returns id associated with this timestamp.
*/
z_id_t z_timestamp_id(const z_timestamp_t *ts);

/**
* Checks validity of a timestamp
*
Expand Down
10 changes: 10 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ int8_t z_bytes_writer_write(z_loaned_bytes_writer_t *writer, const uint8_t *src,
return _z_bytes_writer_write(writer, src, len);
}

int8_t z_timestamp_new(z_timestamp_t *ts, const z_id_t *zid, uint64_t npt64_time) {
ts->id = *zid;
ts->time = npt64_time;
return _Z_RES_OK;
}

uint64_t z_timestamp_npt64_time(const z_timestamp_t *ts) { return ts->time; }

z_id_t z_timestamp_id(const z_timestamp_t *ts) { return ts->id; }

_Bool z_timestamp_check(z_timestamp_t ts) { return _z_timestamp_check(&ts); }

z_query_target_t z_query_target_default(void) { return Z_QUERY_TARGET_DEFAULT; }
Expand Down

0 comments on commit c67de6c

Please sign in to comment.