func (d ID) WorkerID() (wid WorkerID) {
	copy(wid[:], d[workerIDOffset:workerIDOffset+workerIDLength])
	return wid
}
WorkerID returns the underlying worker id
package sandflake
import (
	"bytes"
	"encoding"
	"encoding/base32"
	"encoding/json"
	"fmt"
	"time"
)
const (
	alphabet   = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
	padding    = 6
	encodedLen = 26
	timeUnit   = int64(time.Millisecond)
	timestampLength = 6
	workerIDLength  = 4
	sequenceLength  = 3
	randomLength    = 3
	workerIDOffset = timestampLength
	sequenceOffset = timestampLength + workerIDLength
	randomOffset   = sequenceOffset + sequenceLength
	Size = timestampLength + workerIDLength + sequenceLength + randomLength
)
var (
	Nil   ID
	MaxID = ID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
	maxSequence = MaxID.Sequence()
	globalGenerator Generator
)
var (
	ErrInvalidLength      = fmt.Errorf("expected length of id to be %d", encodedLen)
	ErrInvalidBytesLength = fmt.Errorf("expected length of bytes to be %d", Size)
	encoder      = base32.NewEncoding(alphabet)
	paddingBytes = bytes.Repeat([]byte{'='}, padding)
)
type ID [Size]byte
func NewID(t time.Time, workerID WorkerID, seq uint32, randomBytes []byte) ID {
	var d ID
	ts := uint64(t.UnixNano() / timeUnit)
	d.setTimestamp(ts)
	copy(d[timestampLength:timestampLength+workerIDLength], workerID[:])
	d.setSequence(seq)
	copy(d[randomOffset:], randomBytes)
	return d
}
func Parse(str string) (ID, error) {
	var id ID
	err := id.UnmarshalText([]byte(str))
	if err != nil {
		return id, err
	}
	return id, nil
}
func ParseBytes(b []byte) (ID, error) {
	if len(b) != Size {
		return Nil, ErrInvalidBytesLength
	}
	var id ID
	copy(id[:], b)
	return id, nil
}
func MustParse(str string) ID {
	id, err := Parse(str)
	if err != nil {
		panic(err)
	}
	return id
}
func MustParseBytes(b []byte) ID {
	id, err := ParseBytes(b)
	if err != nil {
		panic(err)
	}
	return id
}
func Next() ID {
	return globalGenerator.Next()
}
func (id ID) String() string {
	b, _ := id.MarshalText()
	return string(b)
}
func (d ID) MarshalText() ([]byte, error) {
	dst := make([]byte, encodedLen+padding)
	encoder.Encode(dst, d[:])
	return dst[:encodedLen], nil
}
func (d *ID) UnmarshalText(b []byte) error {
	if len(b) != encodedLen {
		return ErrInvalidLength
	}
	dst := make([]byte, encodedLen)
	if _, err := encoder.Decode(dst, append(b, paddingBytes...)); err != nil {
		return err
	}
	copy((*d)[:], dst)
	return nil
}
func (d ID) Time() time.Time {
	var ts uint64
	for i := 0; i < timestampLength; i++ {
		ts |= uint64(uint64(d[i]) << uint64((timestampLength-i-1)*8))
	}
	return time.Unix(0, int64(ts)*timeUnit).UTC()
}
func (d *ID) setTimestamp(ts uint64) {
	for i := 0; i < timestampLength; i++ {
		(*d)[i] = byte(ts >> uint64((timestampLength-i-1)*8))
	}
}
func (d *ID) setSequence(ts uint32) {
	n := sequenceOffset + sequenceLength
	for i := sequenceOffset; i < n; i++ {
		(*d)[i] = byte(ts >> uint32((n-i-1)*8))
	}
}