blob: 5528819bd1d366bd3163e4c3224da485d2be37bb (
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
38
|
#include "snowflake.hpp"
Snowflake::Snowflake()
: m_num(Invalid) {}
Snowflake::Snowflake(uint64_t n)
: m_num(n) {}
Snowflake::Snowflake(const std::string &str) {
if (str.size())
m_num = std::stoull(str);
else
m_num = Invalid;
}
Snowflake::Snowflake(const Glib::ustring &str) {
if (str.size())
m_num = std::strtoull(str.c_str(), nullptr, 10);
else
m_num = Invalid;
};
bool Snowflake::IsValid() const {
return m_num != Invalid;
}
void from_json(const nlohmann::json &j, Snowflake &s) {
if (j.is_string()) {
std::string tmp;
j.get_to(tmp);
s.m_num = std::stoull(tmp);
} else {
j.get_to(s.m_num);
}
}
void to_json(nlohmann::json &j, const Snowflake &s) {
j = std::to_string(s);
}
|