nx_id.nx
buildroot/runtime/nx_id.nx
about
nx_id.nx -- monotonic IDs and 128-bit content addresses.
Three ID surfaces, each with explicit guarantees:
nx_seqid_next(ctx) monotonic 64-bit, unique per ctx since
construction. Use for spans, requests,
tasks -- any ordering you only need
within one process lifetime.
nx_uuid7(ctx) time-ordered 128-bit ID, RFC 9562 layout
draft (UUIDv7). Two i64 outputs. The
48 high bits are unix-ms timestamp,
remaining 80 bits are random+counter.
Use across process boundaries when you
need both ordering AND collision-resist.
nx_xid_blake_short 8-byte digest of an arbitrary byte
buffer using a tiny mixing function
(xxhash-style). Use for content
addressing where full SHA-256 is
overkill. NOT cryptographic. For
crypto use sha256.nx / sha512.nx.
Why this file exists separately:
ID generation is touched by every observability module
(nx_log seq, nx_trace span_id, nx_metrics labels) and every
IPC layer (request_id headers). Centralising the policy
prevents drift -- e.g. one module producing 64-bit decimal,
another 128-bit hex, another timestamp-prefixed. All flow
through these three primitives.
Design references:
RFC 9562 (UUIDv7) -- time-ordered v7 layout
Twitter Snowflake -- 64-bit time+machine+seq id
ULID spec -- Crockford-base32 26-char id
xxHash3 -- non-crypto fast mixing function
dependencies 2 imports · 0 importers
imports: syscalls.nxnx_time.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 48 | struct NxIdCtx |
consts
| 46 | const NX_MAGIC_1000000: i64 = 1000000 |
| 53 | const NX_IDCTX_BYTES: i64 = 16 |
functions
| 57 | func nx_id_new(seed: i64) -> *NxIdCtx called by 1: main |
| 68 | func nx_id_xorshift(ctx: *NxIdCtx) -> i64 |
| 79 | func nx_seqid_next(ctx: *NxIdCtx) -> i64 |
| 94 | func nx_uuid7_hi(ctx: *NxIdCtx) -> i64 |
| 106 | func nx_uuid7_lo(ctx: *NxIdCtx) -> i64 |
| 119 | func nx_xid_short(buf: *u8, len: i64) -> i64 called by 1: main |
| 141 | func main() -> i64 |