Skip to content

Commit

Permalink
Allow interfaces with methods and decoding into struct pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcgowan committed Jul 8, 2014
1 parent 71c2886 commit 5d26f5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions codec/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,6 @@ func (f *decFnInfo) kInterface(rv reflect.Value) {
if vt == valueTypeNil {
return
}
// Cannot decode into nil interface with methods (e.g. error, io.Reader, etc)
// if non-nil value in stream.
if num := f.ti.rt.NumMethod(); num > 0 {
decErr("decodeValue: Cannot decode non-nil codec value into nil %v (%v methods)",
f.ti.rt, num)
}
var rvn reflect.Value
var useRvn bool
switch vt {
Expand All @@ -335,7 +329,7 @@ func (f *decFnInfo) kInterface(rv reflect.Value) {
rvn, bfn = f.d.h.getDecodeExtForTag(re.Tag)
if bfn == nil {
rvn = reflect.ValueOf(*re)
} else if fnerr := bfn(rvn, re.Data); fnerr != nil {
} else if fnerr := bfn(rvn.Elem(), re.Data); fnerr != nil {
panic(fnerr)
}
rv.Set(rvn)
Expand Down
2 changes: 1 addition & 1 deletion codec/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (o extHandle) getDecodeExtForTag(tag byte) (
rv reflect.Value, fn func(reflect.Value, []byte) error) {
if x := o.getExtForTag(tag); x != nil {
// ext is only registered for base
rv = reflect.New(x.rt).Elem()
rv = reflect.New(x.rt)
fn = x.decFn
}
return
Expand Down

0 comments on commit 5d26f5f

Please sign in to comment.