Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/FlakeId/Extensions/IdExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ public static long ToUnixTimeMilliseconds(this Id id)
/// <returns></returns>
public static bool IsSnowflake(this Id id)
{
// There's no way to guarantee the specified value is a snowflake.
// The closest we can get is by decomposing its components, and ensuring all of them are set
// to values that would be valid for a snowflake.
// Validates that the ID has a non-zero timestamp.
// Thread , Process, and Increment can legitimately be 0, so checking them for > 0 results in false negatives.
long timestamp = id >> TimestampOffset;
long thread = (id >> ThreadOffset) & Id.ThreadIdMask;
long process = (id >> ProcessOffset) & Id.ProcessIdMask;
long increment = id & Id.IncrementMask;

return timestamp > 0 && thread > 0 && process > 0 && increment >= 0;
return timestamp > 0;
}

/// <summary>
Expand Down
Loading