/
uuid.go
77 lines (60 loc) · 1.33 KB
/
uuid.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
69
70
71
72
73
74
75
76
77
// Copyright ©2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rbase
import (
"reflect"
"go-hep.org/x/hep/groot/rbytes"
"go-hep.org/x/hep/groot/root"
"go-hep.org/x/hep/groot/rtypes"
"go-hep.org/x/hep/groot/rvers"
)
type UUID [16]byte
func (*UUID) Class() string {
return "TUUID"
}
func (*UUID) RVersion() int16 {
return rvers.UUID
}
func (*UUID) Sizeof() int32 {
// UUID-version (u16)
// UUID-payload (16-bytes)
return 18
}
func (uuid *UUID) MarshalROOT(w *rbytes.WBuffer) (int, error) {
if w.Err() != nil {
return 0, w.Err()
}
pos := w.Pos()
w.WriteU16(uint16(uuid.RVersion()))
_, _ = w.Write((*uuid)[:])
end := w.Pos()
return int(end - pos), w.Err()
}
func (uuid *UUID) UnmarshalROOTv1(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}
_, _ = r.Read((*uuid)[:])
return r.Err()
}
func (uuid *UUID) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}
_ = r.ReadU16() // version
_, _ = r.Read((*uuid)[:])
return r.Err()
}
func init() {
f := func() reflect.Value {
o := &UUID{}
return reflect.ValueOf(o)
}
rtypes.Factory.Add("TUUID", f)
}
var (
_ root.Object = (*UUID)(nil)
_ rbytes.Marshaler = (*UUID)(nil)
_ rbytes.Unmarshaler = (*UUID)(nil)
)