Skip to content

Commit

Permalink
groot/rdict: leverage rbytes.{Unm,M}arshaler implementation in Bind
Browse files Browse the repository at this point in the history
This CL adds a temporary mitigation of #880.
It tries to detect whether a given receiver for binding implements rbytes.Unmarshaler and
use it instead of generating rstreamers.

rstreamers may not properly work in the case where fields of a struct aren't exported.

Fixes #880.
  • Loading branch information
sbinet committed Dec 16, 2021
1 parent e370fce commit 07e2951
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions groot/rdict/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func (rr *rstreamerInfo) Bind(recv interface{}) error {
return fmt.Errorf("rdict: invalid kind (got=%T, want=pointer)", recv)
}
rr.recv = recv
if recv, ok := recv.(rbytes.Unmarshaler); ok && rr.kind == rbytes.ObjectWise {
// FIXME(sbinet): handle mbr-/obj-wise
rr.rops = []rstreamer{{
op: func(r *rbytes.RBuffer, _ interface{}, _ *streamerConfig) error {
return recv.UnmarshalROOT(r)
},
cfg: nil,
}}
return nil
}
if len(rr.rops) == 1 {
se := rr.rops[0].cfg.descr.elem
if se.Name() == "This" ||
Expand Down
10 changes: 10 additions & 0 deletions groot/rdict/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (ww *wstreamerInfo) Bind(recv interface{}) error {
return fmt.Errorf("rdict: invalid kind (got=%T, want=pointer)", recv)
}
ww.recv = recv
if recv, ok := recv.(rbytes.Marshaler); ok && ww.kind == rbytes.ObjectWise {
// FIXME(sbinet): handle mbr-/obj-wise
ww.wops = []wstreamer{{
op: func(w *rbytes.WBuffer, _ interface{}, _ *streamerConfig) (int, error) {
return recv.MarshalROOT(w)
},
cfg: nil,
}}
return nil
}
if len(ww.wops) == 1 && ww.wops[0].cfg.descr.elem.Name() == "This" {
// binding directly to 'recv'. assume no offset is to be applied
ww.wops[0].cfg.offset = -1
Expand Down
3 changes: 3 additions & 0 deletions groot/rdict/rdict.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (si *StreamerInfo) build(sictx rbytes.StreamerInfoContext) error {
for i, descr := range si.descr {
si.roops = append(si.roops, si.makeROp(sictx, i, descr))
si.woops = append(si.woops, si.makeWOp(sictx, i, descr))
// FIXME(sbinet): handle member-wise r/w ops
// si.rmops
// si.wmops
}

return nil
Expand Down

0 comments on commit 07e2951

Please sign in to comment.