Skip to content

marcomagdy/ulid

Repository files navigation

libulid

Linux build badge CodeQL badge

Lightweight ulid implementation in C++ suitable for embedded environments:

  1. No dynamic allocations
  2. No C++ Exceptions
  3. Thread-safe

Installation

  • Copy ulid.cpp and ulid.h files to your project. That's it.

  • You can also build it from source and install it via CMake.

$ cmake -B build -DCMAKE_BUILD_TYPE=Release
$ cmake --build build
$ cmake --install build

API

No dynamic allocation:

  char ulid_str[27]; // 26 characters + null terminator
  ulid::generate(ulid_str);
  printf("%s\n", ulid_str); // ulid_str is null-terminated

Simple API:

  std::string unique = ulid::generate().str();

Decode a ULID string back to bytes:

  const char some_ulid[] = "01GF428XRREWQWJHXRRGNN99NV";
  ulid::ulid_t bits = ulid::from_str(some_ulid);