Skip to content

Commit

Permalink
groot/rbytes: introduce RSlicer interface
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed Sep 7, 2023
1 parent 8631271 commit 8795bae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 12 additions & 0 deletions groot/rbytes/rbytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ const (
BypassStreamer uint32 = 1 << 12
CannotHandleMemberWiseStreaming uint32 = 1 << 17
)

// Member is a ROOT member of a ROOT class.
type Member struct {
Name string
Value any
}

// RSlicer wraps the RMembers method.
type RSlicer interface {
// RMembers returns the list of (pointers to) members of a given ROOT value.
RMembers() []Member
}
17 changes: 7 additions & 10 deletions groot/rcont/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package rcont

import (
"fmt"
"io"
"reflect"

"go-hep.org/x/hep/groot/rbase"
Expand All @@ -20,13 +19,15 @@ type List struct {
obj rbase.Object
name string
objs []root.Object
opts []string
}

func NewList(name string, objs []root.Object) *List {
list := &List{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
name: name,
objs: objs,
opts: make([]string, len(objs)),
}
return list
}
Expand Down Expand Up @@ -68,6 +69,7 @@ func (li *List) Len() int {

func (li *List) Append(obj root.Object) {
li.objs = append(li.objs, obj)
li.opts = append(li.opts, "")
}

func (li *List) MarshalROOT(w *rbytes.WBuffer) (int, error) {
Expand All @@ -79,9 +81,9 @@ func (li *List) MarshalROOT(w *rbytes.WBuffer) (int, error) {
w.WriteObject(&li.obj)
w.WriteString(li.name)
w.WriteI32(int32(len(li.objs)))
for _, obj := range li.objs {
for i, obj := range li.objs {
w.WriteObjectAny(obj)
w.WriteU8(0) // FIXME(sbinet): properly serialize the 'OPTION'.
w.WriteString(li.opts[i])
}

return w.SetHeader(hdr)
Expand All @@ -105,6 +107,7 @@ func (li *List) UnmarshalROOT(r *rbytes.RBuffer) error {
size := int(r.ReadI32())

li.objs = make([]root.Object, size)
li.opts = make([]string, size)

for i := range li.objs {
obj := r.ReadObjectAny()
Expand All @@ -114,13 +117,7 @@ func (li *List) UnmarshalROOT(r *rbytes.RBuffer) error {
// return r.Err()
}
li.objs[i] = obj

n := int(r.ReadU8())
if n > 0 {
opt := make([]byte, n)
_, _ = io.ReadFull(r, opt)
// drop the option on the floor. // FIXME(sbinet)
}
li.opts[i] = r.ReadString()
}

r.CheckHeader(hdr)
Expand Down
2 changes: 2 additions & 0 deletions groot/rcont/rw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestWRBuffer(t *testing.T) {
rbase.NewNamed("n0", "t0"),
rbase.NewNamed("n1", "t1"),
},
opts: []string{"opt1", "opt2"},
},
},
{
Expand Down Expand Up @@ -338,6 +339,7 @@ var rwBufferCases = []struct {
rbase.NewNamed("n0", "t0"),
rbase.NewNamed("n1", "t1"),
},
opts: []string{"", ""},
},
},
{
Expand Down

0 comments on commit 8795bae

Please sign in to comment.