summaryrefslogtreecommitdiff
path: root/infra/session_manager/test/session_id_decoder.cpp
blob: e0a68fb1def183c4584e9f798b34ec79a2aaa474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.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]);

    uint64_t sequence = id & 0x7FFF;
    uint64_t time_relative = (id >> 15) & 0xFFFFFFF;
    uint64_t seed = (id >> 43) & 0xFFFFF;

    uint64_t thread_id = seed & 0xFF;
    uint64_t instance_id = (seed >> 8) & 0xFFF;

    printf("id: %lu, seed: %lu, instance_id: %lu, thread_id: %lu, time_relative: %lu, sequence: %lu\n", id, seed, instance_id, thread_id, time_relative, sequence);

#define MAX_ID_BASE_TIME (268435456L)

    for (int i = 6; i < 10; i++)
    {
        char buff[64];
        time_t tt = MAX_ID_BASE_TIME * i + time_relative;
        struct tm *tm = localtime(&tt);
        strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", tm);
        printf("\ttime_period * %d + time_relative => %s\n", i, buff);
    }

    return 0;
}