-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy patharray.go
69 lines (53 loc) · 1.35 KB
/
array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package uuid
/****************
* Date: 1/02/14
* Time: 10:08 AM
***************/
const (
variantIndex = 8
versionIndex = 6
)
// A clean UUID type for simpler UUID versions
type UUIDArray [length]byte
func (UUIDArray) Size() int {
return length
}
func (o UUIDArray) Version() int {
return int(o[versionIndex]) >> 4
}
func (o *UUIDArray) setVersion(pVersion int) {
o[versionIndex] &= 0x0F
o[versionIndex] |= byte(pVersion)<<4
}
func (o *UUIDArray) Variant() byte {
return variant(o[variantIndex])
}
func (o *UUIDArray) setVariant(pVariant byte) {
setVariant(&o[variantIndex], pVariant)
}
func (o *UUIDArray) Unmarshal(pData []byte) {
copy(o[:], pData)
}
func (o *UUIDArray) Bytes() []byte {
return o[:]
}
func (o UUIDArray) String() string {
return formatter(&o, format)
}
func (o UUIDArray) Format(pFormat Format) string {
return formatter(&o, pFormat)
}
// Set the three most significant bits (bits 0, 1 and 2) of the
// sequenceHiAndVariant equivalent in the array to ReservedRFC4122.
func (o *UUIDArray) setRFC4122Variant() {
o[variantIndex] &= 0x3F
o[variantIndex] |= ReservedRFC4122
}
// Marshals the UUID bytes into a slice
func (o *UUIDArray) MarshalBinary() ([]byte, error) {
return o.Bytes(), nil
}
// Un-marshals the data bytes into the UUID.
func (o *UUIDArray) UnmarshalBinary(pData []byte) (error) {
return UnmarshalBinary(o, pData)
}