A container for a 64 bit unsigned value representing many things on discord. This value is known in distributed computing as a snowflake value.
More...
|
constexpr | snowflake () noexcept=default |
| Construct a snowflake object. More...
|
|
constexpr | snowflake (const snowflake &rhs) noexcept=default |
| Copy a snowflake object. More...
|
|
constexpr | snowflake (snowflake &&rhs) noexcept=default |
| Move a snowflake object. More...
|
|
template<typename T , typename = std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>>> |
constexpr | snowflake (T snowflake_val) noexcept(std::is_unsigned_v< T >) |
| Construct a snowflake from an integer value. More...
|
|
| snowflake (std::string_view string_value) noexcept |
| Construct a snowflake object from an unsigned integer in a string. More...
|
|
template<typename T , typename = std::enable_if_t<std::is_same_v<T, std::string>>> |
| snowflake (const T &string_value) noexcept |
| Construct a snowflake object from an unsigned integer in a string. More...
|
|
constexpr dpp::snowflake & | operator= (const dpp::snowflake &rhs) noexcept=default |
| Copy value from another snowflake. More...
|
|
constexpr dpp::snowflake & | operator= (dpp::snowflake &&rhs) noexcept=default |
| Move value from another snowflake. More...
|
|
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>> |
constexpr dpp::snowflake & | operator= (T snowflake_val) noexcept(std::is_unsigned_v< T >) |
| Assign integer value to the snowflake. More...
|
|
template<typename T , typename = std::enable_if_t<std::is_convertible_v<T, std::string_view>>> |
constexpr dpp::snowflake & | operator= (T &&snowflake_val) noexcept |
| Assign value converted from a string to the snowflake. More...
|
|
constexpr bool | empty () const noexcept |
| Returns true if the snowflake holds an empty value (is 0) More...
|
|
std::string | str () const |
| Returns the stringified version of the snowflake value. More...
|
|
constexpr bool | operator== (dpp::snowflake snowflake_val) const noexcept |
| Comparison operator with another snowflake. More...
|
|
bool | operator== (std::string_view snowflake_val) const noexcept |
| Comparison operator with a string. More...
|
|
template<typename T , typename = std::enable_if_t<std::is_integral_v<T>>> |
constexpr bool | operator== (T snowflake_val) const noexcept |
| Comparison operator with an integer. More...
|
|
constexpr | operator uint64_t () const noexcept |
| For acting like an integer. More...
|
|
constexpr | operator uint64_t & () noexcept |
| For acting like an integer. More...
|
|
| operator json () const |
| For building json. More...
|
|
constexpr double | get_creation_time () const noexcept |
| Get the creation time of this snowflake according to Discord. More...
|
|
constexpr uint8_t | get_worker_id () const noexcept |
| Get the worker id that produced this snowflake value. More...
|
|
constexpr uint8_t | get_process_id () const noexcept |
| Get the process id that produced this snowflake value. More...
|
|
constexpr uint16_t | get_increment () const noexcept |
| Get the increment, which is incremented for every snowflake created over the one millisecond resolution in the timestamp. More...
|
|
A container for a 64 bit unsigned value representing many things on discord. This value is known in distributed computing as a snowflake value.
Snowflakes are:
- Performant (very fast to generate at source and to compare in code)
- Uncoordinated (allowing high availability across clusters, data centres etc)
- Time ordered (newer snowflakes have higher IDs)
- Directly Sortable (due to time ordering)
- Compact (64 bit numbers, not 128 bit, or string)
An identical format of snowflake is used by Twitter, Instagram and several other platforms.
- See also
- https://en.wikipedia.org/wiki/Snowflake_ID
-
https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231