aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/twinj/uuid/array.go
blob: add7e19bea12afeccd1e71a2989a262a1aa934e7 (plain)
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 Array [length]byte

func (Array) Size() int {
	return length
}

func (o Array) Version() int {
	return int(o[versionIndex]) >> 4
}

func (o *Array) setVersion(pVersion int) {
	o[versionIndex] &= 0x0F
	o[versionIndex] |= byte(pVersion) << 4
}

func (o *Array) Variant() byte {
	return variant(o[variantIndex])
}

func (o *Array) setVariant(pVariant byte) {
	setVariant(&o[variantIndex], pVariant)
}

func (o *Array) Unmarshal(pData []byte) {
	copy(o[:], pData)
}

func (o *Array) Bytes() []byte {
	return o[:]
}

func (o Array) String() string {
	return formatter(&o, format)
}

func (o Array) Format(pFormat string) 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 *Array) setRFC4122Variant() {
	o[variantIndex] &= 0x3F
	o[variantIndex] |= ReservedRFC4122
}

// Marshals the UUID bytes into a slice
func (o *Array) MarshalBinary() ([]byte, error) {
	return o.Bytes(), nil
}

// Un-marshals the data bytes into the UUID.
func (o *Array) UnmarshalBinary(pData []byte) error {
	return UnmarshalBinary(o, pData)
}