Skip to content

Commit

Permalink
account for the fact that we could be trying to decode nil, because w…
Browse files Browse the repository at this point in the history
…e want to read past the next ResponseBody
  • Loading branch information
erikstmartin committed Sep 20, 2013
1 parent 9651373 commit 62a2589
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rpc/bsonrpc/bsoncoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func NewDecoder(r io.Reader) *Decoder {
}

func (d *Decoder) Decode(pv interface{}) (err error) {
rv := reflect.ValueOf(pv)
log.Println(log.TRACE, "Decoding into: ", rv.Type())
if pv != nil {
rv := reflect.ValueOf(pv)
log.Println(log.TRACE, "Decoding into: ", rv.Type())
}

var lbuf [4]byte
n, err := d.r.Read(lbuf[:])
Expand Down Expand Up @@ -80,7 +82,9 @@ func (d *Decoder) Decode(pv interface{}) (err error) {
log.Println(log.ERROR, "Error decoding message (reading message): ", err)
}

err = bson.Unmarshal(buf, pv)
if pv != nil {
err = bson.Unmarshal(buf, pv)
}

return
}

0 comments on commit 62a2589

Please sign in to comment.