-
Notifications
You must be signed in to change notification settings - Fork 35
/
descr.go
58 lines (49 loc) · 1.39 KB
/
descr.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
// Copyright 2020 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 rdict
import (
"reflect"
"go-hep.org/x/hep/groot/rbytes"
"go-hep.org/x/hep/groot/rmeta"
)
// type arrayMode int32
type elemDescr struct {
otype rmeta.Enum
ntype rmeta.Enum
offset int // actually an index to the struct's field or to array's element
length int
elem rbytes.StreamerElement
method []int
oclass string
nclass string
mbr interface{} // member streamer
}
type streamerConfig struct {
si *StreamerInfo
eid int // element ID
descr *elemDescr
offset int // offset/index within object. negative if no offset to be applied.
length int // number of elements for fixed-length arrays
count func() int // optional func to give the length of ROOT's C var-len arrays.
}
func (cfg *streamerConfig) counter(recv interface{}) int {
if cfg.count != nil {
return cfg.count()
}
return int(reflect.ValueOf(recv).Elem().FieldByIndex(cfg.descr.method).Int())
}
func (cfg *streamerConfig) adjust(recv interface{}) interface{} {
if cfg == nil || cfg.offset < 0 {
return recv
}
rv := reflect.ValueOf(recv).Elem()
switch rv.Kind() {
case reflect.Struct:
return rv.Field(cfg.offset).Addr().Interface()
case reflect.Array, reflect.Slice:
return rv.Index(cfg.offset).Addr().Interface()
default:
return recv
}
}