Documentation
¶
Overview ¶
Package sne generates snowflake like 128 bit ids that uses milliseconds for the time element. A sne Flake has a 41 bit time field, a 11 bit sequence, a 56 bit ID, and a 20 bit secondary id. The time field holds milliseconds since 1/1/2016 00:00:00. The sequence starts at a random position and increments with each Snowflake. If there is the possibility of needing more than 2,048,000 Flakes per second for a given ID and secondary ID combination this package should not be used.
Data layout:
0-40 time, in milliseconds: 69 years 41-51 sequence; for collision prevention 52-71 secondary id 72-127 primary ID
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flake ¶
type Flake [16]byte
Flake is the type for a 128 bit snowflake.
func (*Flake) ID ¶
ID returns the Flake's ID as a []byte. A snowflake's ID is the last 8 bytes. No assumptios are made about either the contents of those bytes or their layout, that is left up to the user.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator creates snowflakes for a given id
func New ¶
New returns an initialized generator. If the passed byte slice's length is greater than 7 bytes, the first 7 bytes will be used for the generator's id. If the passed byte slice's length is less than 7 bytes, the id will be left- padded with 0x00. The id2 parameter is the secondary id: only the right- most 20 bits are used. The generator's sequence is initialized with a random int within [0, 2^11).