Skip to content

Tiny, fast, and portable library to generate Snowflake IDs for C applications

License

Notifications You must be signed in to change notification settings

thibaultmeyer/libsnowflakeid

Repository files navigation

libsnowflakeid

Latest release GitHub license CodeFactor Repository size

A tiny and portable library to generate Snowflake IDs.


Build & install from sources

To compile and install this project, you must ensure that make, cmake, gcc or clang or MSVC are being correctly installed.

#> mkdir cmake-build-release
#> cd cmake-build-release
#> cmake -DCMAKE_BUILD_TYPE=Release ..
#> make
#> make install

Usage

#include <snowflakeid.h>

int main(const int argc, const char *const *argv) {
    enum e_snowflakeid_init_status     status_out;
    struct s_snowflakeid_generator_ctx *ctx = snowflakeid_initialize(
            datacenter_id,
            worker_id,
            offset_time_ms,
            &status_out);
    
    if (status_out == SNOWFLAKEID_INIT_SUCCESS) {
        uint64_t id = snowflakeid_next_value(ctx);
        
        snowflakeid_destroy(ctx);
    }
    
    return (0);
}
#> cc example.c -lsnowflakeid

License

This project is released under terms of the MIT license.