32 lines
619 B
C
32 lines
619 B
C
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
|
|
struct snowflake;
|
|
struct snowflake *snowflake_new(uint16_t thread_id, uint8_t worker_base_id, uint8_t worker_offset_id);
|
|
void snowflake_free(struct snowflake *sf);
|
|
|
|
struct snowflake_meta
|
|
{
|
|
uint64_t sequence;
|
|
uint64_t time_cycle;
|
|
uint64_t time_relative;
|
|
uint16_t thread_id;
|
|
uint16_t device_id;
|
|
|
|
uint8_t worker_base_id;
|
|
uint8_t worker_offset_id;
|
|
};
|
|
|
|
uint64_t snowflake_generate(struct snowflake *sf, uint64_t now_sec);
|
|
void snowflake_deserialize(uint64_t id, struct snowflake_meta *meta);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|