mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
30 lines
546 B
C++
30 lines
546 B
C++
#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;
|
|
};
|
|
|
|
bool Snowflake::IsValid() const {
|
|
return m_num != Invalid;
|
|
}
|
|
|
|
void from_json(const nlohmann::json &j, Snowflake &s) {
|
|
std::string tmp;
|
|
j.get_to(tmp);
|
|
s.m_num = std::stoull(tmp);
|
|
}
|
|
|
|
void to_json(nlohmann::json &j, const Snowflake &s) {
|
|
j = std::to_string(s);
|
|
}
|