This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/infra/snowflake/test/snowflake_tool.cpp

38 lines
1.1 KiB
C++
Raw Normal View History

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "snowflake.h"
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("Usage: %s <id>\n", argv[0]);
return -1;
}
uint64_t id = atoll(argv[1]);
struct snowflake_meta meta = {};
snowflake_deserialize(id, &meta);
printf("id : %lu\n", id);
printf("base_id : %u\n", meta.worker_base_id);
printf("offset_id : %u\n", meta.worker_offset_id);
printf("device_id : %u\n", meta.device_id);
printf("thread_id : %u\n", meta.thread_id);
printf("time_cycle : %lu sec (%lu year)\n", meta.time_cycle, meta.time_cycle / 3600 / 24 / 365);
printf("time_relative : %lu sec\n", meta.time_relative);
printf("sequence : %lu\n", meta.sequence);
for (int i = 6; i < 10; i++)
{
char buff[64];
time_t tt = meta.time_cycle * i + meta.time_relative;
struct tm *tm = localtime(&tt);
strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", tm);
printf("\ttime_cycle * %d + time_relative => %s\n", i, buff);
}
return 0;
}