diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 8bbec6b37..c7ee618fa 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -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 * diff --git a/src/api/api.c b/src/api/api.c index 0dc1232a1..63cf626ce 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -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; }