coolaj86 / zig-uuidv7

UUIDv7, written in Zig
Other
0 stars 1 forks source link

zig-uuidv7

Generate UUID v7 strings, like 019212d3-87f4-7d25-902e-b8d39fe07f08.

uuidv7 > uuidv7.txt
019212d3-87f4-7d25-902e-b8d39fe07f08
32-bit time 16-bit time 4 ver + 12 rnd 2 var + 14 rnd 16 rnd + 32 rnd
01 92 12 d3 87 f4 7d 25 90 2e b8 d3 9f e0 7f 08

Table of Contents

Install

Pre-built archives available for Mac, Linux, & Widows. \ Compile from source for FreeBSD, OpenBSD, etc.

  1. Download from GitHub Releases: https://github.com/coolaj86/zig-uuidv7/releases
  2. Extract
  3. Place in your PATH
b_triplet='x86_64-linux-musl'
curl -L -O https://github.com/coolaj86/zig-uuidv7/releases/download/v1.0.0/uuidv7-v1.0.0-"$b_triplet".tar.gz
tar xvf ./uuidv7-v1.0.0-"$b_triplet".tar.gz
mv ./uuidv7 ~/bin/

UUIDv7 Spec

By the Characters

There are 36 characters total: 32 hex (0123456789abcdef) + 4 dashes (-)

  8 time    4 time    1v + 3ra   ½v + 3½rb    12 random b
019212d3  -  87f4   -   7d25   -   902e   -   b8d39fe07f08

By the Bits

   48 time         4ver, 12ra   2var, 14rb        random b
019212d3-87f4    -    7d25    -    902e    -    b8d39fe07f08

Build

See </build.sh>.

Builds with zig v0.13 and the v0.14 previews so far.

curl https://webi.sh/zig@0.13 | sh
source ~/.config/envman/PATH.env
zig build-exe ./uuidv7.zig -O ReleaseSmall -femit-bin="uuidv7"

for b_target in x86-linux-musl aarch64-macos-none x86_64-windows-gnu; do
    zig build-exe ./uuidv7.zig -O ReleaseSmall \
        -target "${b_target}" -femit-bin="uuidv7-${b_target}"
done

License

Copyright 2024 AJ ONeal aj@therootcompany.com

This Source Code Form is subject to the terms of the Mozilla Public \ License, v. 2.0. If a copy of the MPL was not distributed with this \ file, You can obtain one at https://mozilla.org/MPL/2.0/.