MCPcopy
hub / github.com/google/uuid / NewV6

Function NewV6

version6.go:21–56  ·  view source on GitHub ↗

UUID version 6 is a field-compatible version of UUIDv1, reordered for improved DB locality. It is expected that UUIDv6 will primarily be used in contexts where there are existing v1 UUIDs. Systems that do not involve legacy UUIDv1 SHOULD consider using UUIDv7 instead. see https://datatracker.ietf.o

()

Source from the content-addressed store, hash-verified

19// SetClockSequence then it will be set automatically. If GetTime fails to
20// return the current NewV6 returns Nil and an error.
21func NewV6() (UUID, error) {
22 var uuid UUID
23 now, seq, err := GetTime()
24 if err != nil {
25 return uuid, err
26 }
27
28 /*
29 0 1 2 3
30 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
31 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 | time_high |
33 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 | time_mid | time_low_and_version |
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 |clk_seq_hi_res | clk_seq_low | node (0-1) |
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | node (2-5) |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 */
41
42 binary.BigEndian.PutUint64(uuid[0:], uint64(now))
43 binary.BigEndian.PutUint16(uuid[8:], seq)
44
45 uuid[6] = 0x60 | (uuid[6] & 0x0F)
46 uuid[8] = 0x80 | (uuid[8] & 0x3F)
47
48 nodeMu.Lock()
49 if nodeID == zeroID {
50 setNodeInterface("")
51 }
52 copy(uuid[10:], nodeID[:])
53 nodeMu.Unlock()
54
55 return uuid, nil
56}

Callers 1

TestVersion6Function · 0.85

Calls 2

GetTimeFunction · 0.85
setNodeInterfaceFunction · 0.85

Tested by 1

TestVersion6Function · 0.68