-
Notifications
You must be signed in to change notification settings - Fork 35
/
objstring.go
97 lines (80 loc) · 1.93 KB
/
objstring.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright ©2017 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 (
"fmt"
"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 ObjString struct {
obj Object
str string
}
// NewObjString creates a new ObjString.
func NewObjString(s string) *ObjString {
return &ObjString{
obj: *NewObject(),
str: s,
}
}
func (*ObjString) RVersion() int16 {
return rvers.ObjString
}
func (*ObjString) Class() string {
return "TObjString"
}
func (obj *ObjString) UID() uint32 {
return obj.obj.UID()
}
func (obj *ObjString) Name() string {
return obj.str
}
func (*ObjString) Title() string {
return "Collectable string class"
}
func (obj *ObjString) String() string {
return obj.str
}
// ROOTUnmarshaler is the interface implemented by an object that can
// unmarshal itself from a ROOT buffer
func (obj *ObjString) UnmarshalROOT(r *rbytes.RBuffer) error {
hdr := r.ReadHeader(obj.Class())
if hdr.Vers > rvers.ObjString {
panic(fmt.Errorf(
"rbase: invalid %s version=%d > %d",
obj.Class(), hdr.Vers, rvers.ObjString,
))
}
r.ReadObject(&obj.obj)
obj.str = r.ReadString()
r.CheckHeader(hdr)
return r.Err()
}
func (obj *ObjString) MarshalROOT(w *rbytes.WBuffer) (int, error) {
if w.Err() != nil {
return 0, w.Err()
}
hdr := w.WriteHeader(obj.Class(), obj.RVersion())
w.WriteObject(&obj.obj)
w.WriteString(obj.str)
return w.SetHeader(hdr)
}
func init() {
f := func() reflect.Value {
o := &ObjString{}
return reflect.ValueOf(o)
}
rtypes.Factory.Add("TObjString", f)
}
var (
_ root.Object = (*ObjString)(nil)
_ root.UIDer = (*ObjString)(nil)
_ root.Named = (*ObjString)(nil)
_ root.ObjString = (*ObjString)(nil)
_ rbytes.Marshaler = (*ObjString)(nil)
_ rbytes.Unmarshaler = (*ObjString)(nil)
)