newTimestamp method

Timestamp newTimestamp()

Creates a new timestamp from this session's HLC clock.

Works on a default peer session (no timestamping/enabled required).

Throws StateError if the session has been closed. Throws ZenohException if the native timestamp creation fails.

Implementation

Timestamp newTimestamp() {
  _ensureOpen();
  final tsSize = bindings.zd_timestamp_sizeof();
  assert(tsSize == 24, 'z_timestamp_t drifted from 24 bytes: $tsSize');
  final outTs = calloc<Uint8>(tsSize);
  try {
    final loanedSession = bindings.zd_session_loan(_ptr.cast());
    final rc = bindings.zd_timestamp_new(loanedSession, outTs);
    if (rc != 0) throw ZenohException('Failed to create timestamp', rc);
    return Timestamp.fromRaw(outTs.asTypedList(tsSize));
  } finally {
    calloc.free(outTs);
  }
}