Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Snowflakes to valid range #382

Closed
wants to merge 4 commits into from

Conversation

lukellmann
Copy link
Member

This PR implements the Snowflake limitations described in discord/discord-api-docs#3745.

The valid range for a Snowflake's raw value is represented by the new validULongRange property of Snowflake's companion object. All constructors will coerce their input in that range so there is no way to create an invalid Snowflake.
If Discord ever decides to widen the valid range, it would just be a matter of adjusting the validULongRange accordingly to support that. (I intended this range to be the single point of truth).

b96f3bb removes a test that was depending on an invalid Snowflake to pass. Since there is no longer a way to create such invalid Snowflakes, it was impossible to make this test pass.

This PR should be merged after #381 as it reverts (46c7462) the changes made there and replaces them with a more permanent solution.
I would also want to keep this PR open until discord/discord-api-docs#3745 gets accepted.

*
* Note that this range might change in the future.
*/
val validULongRange: ULongRange = ULong.MIN_VALUE..Long.MAX_VALUE.toULong() // 0..9223372036854775807
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use literals here?
like: val validULongRange: ULongRange = 0uL..9223372036854775807uL

@lukellmann lukellmann closed this Sep 2, 2021
@lukellmann lukellmann deleted the fixes/snowflake-limits branch February 17, 2022 01:18
@lukellmann lukellmann restored the fixes/snowflake-limits branch February 17, 2022 01:18
@lukellmann lukellmann deleted the fixes/snowflake-limits branch February 17, 2022 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant