github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/snow/id.go (about) 1 package snow 2 3 // An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID. 4 type ID int64 5 6 // TimeOf returns an int64 unix timestamp in milliseconds of the snowflake ID time 7 func (n *Node) TimeOf(f ID) int64 { return (int64(f) >> n.timeShift) + n.epoch } 8 9 // NodeIDOf returns an int64 of the snowflake ID node number 10 func (n *Node) NodeIDOf(f ID) int64 { return int64(f) & n.nodeMask >> n.nodeShift } 11 12 // StepOf returns an int64 of the snowflake step (or sequence) number 13 func (n *Node) StepOf(f ID) int64 { return int64(f) & n.stepMask } 14 15 // Time returns an int64 unix timestamp in milliseconds of the snowflake ID time 16 func (f ID) Time() int64 { return DefaultNode.TimeOf(f) } 17 18 // NodeID returns an int64 of the snowflake ID node number 19 func (f ID) NodeID() int64 { return DefaultNode.NodeIDOf(f) } 20 21 // Step returns an int64 of the snowflake step (or sequence) number 22 func (f ID) Step() int64 { return DefaultNode.StepOf(f) }