dpp::snowflake
snowflake.h
uint64_t uint64_t format_as (snowflake s) noexcept format_as dpp::snowflake::format_as snowflake s

Helper function for libfmt so that a snowflake can be directly formatted as a uint64_t.

https://fmt.dev/latest/api.html#formatting-user-defined-types

uint64_t snowflake ID

struct friend struct std::hash< dpp::snowflake > std::hash< dpp::snowflake > dpp::snowflake::hash< dpp::snowflake > std::hash< dpp::snowflake >
uint64_t uint64_t dpp::snowflake::value value dpp::snowflake::value = 0

The snowflake value.

constexpr dpp::snowflake::snowflake () noexcept=default snowflake dpp::snowflake::snowflake

Construct a snowflake object.

constexpr dpp::snowflake::snowflake (const snowflake &rhs) noexcept=default snowflake dpp::snowflake::snowflake const snowflake & rhs

Copy a snowflake object.

typename T
typename std::enable_if_t<std::is_same_v<T, std::string>>
dpp::snowflake::snowflake
(const T &string_value) noexcept
snowflake
dpp::snowflake::snowflake
const T & string_value

Construct a snowflake object from an unsigned integer in a string.

On invalid string the value will be 0 string_value

A snowflake value

constexpr dpp::snowflake::snowflake (snowflake &&rhs) noexcept=default snowflake dpp::snowflake::snowflake snowflake && rhs

Move a snowflake object.

dpp::snowflake::snowflake
(std::string_view string_value) noexcept
snowflake
dpp::snowflake::snowflake
std::string_view string_value

Construct a snowflake object from an unsigned integer in a string.

On invalid string the value will be 0 string_value

A snowflake value

typename T
typename std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>>
constexpr dpp::snowflake::snowflake (T snowflake_val) snowflake dpp::snowflake::snowflake T snowflake_val

Construct a snowflake from an integer value.

dpp::logic_exception

on assigning a negative value. The function is noexcept if the type given is unsigned

snowflake_val

snowflake value as an integer type

we cast to the unsigned version of the type given - this maintains "possible loss of data" warnings for sizeof(T) > sizeof(value) while suppressing them for signed to unsigned conversion (for example snowflake(42) will call snowflake(int) which is a signed type)

bool bool dpp::snowflake::empty () const noexcept empty dpp::snowflake::empty

Returns true if the snowflake holds an empty value (is 0).

true if empty (zero)

double double dpp::snowflake::get_creation_time () const noexcept get_creation_time dpp::snowflake::get_creation_time

Get the creation time of this snowflake according to Discord.

double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

uint16_t uint16_t dpp::snowflake::get_increment () const noexcept get_increment dpp::snowflake::get_increment

Get the increment, which is incremented for every snowflake created over the one millisecond resolution in the timestamp.

uint64_t millisecond increment

uint8_t uint8_t dpp::snowflake::get_process_id () const noexcept get_process_id dpp::snowflake::get_process_id

Get the process id that produced this snowflake value.

uint8_t process id

uint8_t uint8_t dpp::snowflake::get_worker_id () const noexcept get_worker_id dpp::snowflake::get_worker_id

Get the worker id that produced this snowflake value.

uint8_t worker id

dpp::snowflake::operator json
() const
operator json
dpp::snowflake::operator json

For building json.

The snowflake value as a string

constexpr dpp::snowflake::operator uint64_t () const noexcept operator uint64_t dpp::snowflake::operator uint64_t

For acting like an integer.

The snowflake value

constexpr dpp::snowflake::operator uint64_t & () noexcept operator uint64_t & dpp::snowflake::operator uint64_t &

For acting like an integer.

A reference to the snowflake value

dpp::snowflake & dpp::snowflake & dpp::snowflake::operator= (const dpp::snowflake &rhs) noexcept=default operator= dpp::snowflake::operator= const dpp::snowflake & rhs

Copy value from another snowflake.

rhs

The snowflake to copy from

dpp::snowflake & dpp::snowflake & dpp::snowflake::operator= (dpp::snowflake &&rhs) noexcept=default operator= dpp::snowflake::operator= dpp::snowflake && rhs

Move value from another snowflake.

rhs

The snowflake to move from

typename T
typename std::enable_if_t<std::is_convertible_v<T, std::string_view>>
dpp::snowflake & dpp::snowflake & dpp::snowflake::operator= (T &&snowflake_val) noexcept operator= dpp::snowflake::operator= T && snowflake_val

Assign value converted from a string to the snowflake.

On invalid string the value will be 0 snowflake_val

snowflake value as a string

typename T
typename std::enable_if_t<std::is_integral_v<T>>
dpp::snowflake & dpp::snowflake & dpp::snowflake::operator= (T snowflake_val) operator= dpp::snowflake::operator= T snowflake_val

Assign integer value to the snowflake.

dpp::logic_exception

on assigning a negative value. The function is noexcept if the type given is unsigned

snowflake_val

snowflake value as an integer type

bool bool dpp::snowflake::operator== (dpp::snowflake snowflake_val) const noexcept operator== dpp::snowflake::operator== dpp::snowflake snowflake_val

Comparison operator with another snowflake.

snowflake_val

snowflake

bool bool dpp::snowflake::operator== (std::string_view snowflake_val) const noexcept operator== dpp::snowflake::operator== std::string_view snowflake_val

Comparison operator with a string.

snowflake_val

snowflake value as a string

typename T
typename std::enable_if_t<std::is_integral_v<T>>
bool bool dpp::snowflake::operator== (T snowflake_val) const noexcept operator== dpp::snowflake::operator== T snowflake_val

Comparison operator with an integer.

snowflake_val

snowflake value as an integer type

std::string std::string dpp::snowflake::str () const str dpp::snowflake::str

Returns the stringified version of the snowflake value.

std::string string form of snowflake value

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.

https://en.wikipedia.org/wiki/Snowflake_ID

https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231

dpp::snowflake
value
uint64_t
- dpp::snowflake
  empty
- dpp::snowflake
  format_as
- dpp::snowflake
  get_creation_time
- dpp::snowflake
  get_increment
- dpp::snowflake
  get_process_id
- dpp::snowflake
  get_worker_id
- dpp::snowflake
  operator json
- dpp::snowflake
  operator uint64_t
- dpp::snowflake
  operator uint64_t &
- dpp::snowflake
  operator=
- dpp::snowflake
  operator=
- dpp::snowflake
  operator=
- dpp::snowflake
  operator=
- dpp::snowflake
  operator==
- dpp::snowflake
  operator==
- dpp::snowflake
  operator==
- dpp::snowflake
  snowflake
- dpp::snowflake
  snowflake
- dpp::snowflake
  snowflake
- dpp::snowflake
  snowflake
- dpp::snowflake
  snowflake
- dpp::snowflake
  snowflake
- dpp::snowflake
  std::hash< dpp::snowflake >
- dpp::snowflake
  str
- dpp::snowflake
  value