Snowflake.parse constructor

Snowflake.parse(
  1. Object value
)

Parse a string or integer value to a snowflake.

Both data types are accepted as Discord's Gateway can transmit Snowflakes as strings or integers when using the GatewayPayloadFormat.etf payload format.

The value must be an int or a String parsable by int.parse.

Snowflakes are generally unique across the API except in some cases where children share their parent's IDs.

{@template snowflake_ordering} Snowflakes are ordered first by their timestamp, then by workerId, processId and increment. The last three fields are only used internally by Discord so the only ordering visible through the API is by timestamp.

Implementation

// TODO: This method will fail once snowflakes become larger than 2^63.
// We need to parse the unsigned [value] into a signed [int].
factory Snowflake.parse(Object /* String | int */ value) {
  assert(value is String || value is int);

  if (value is! int) {
    value = int.parse(value.toString());
  }

  return Snowflake(value);
}