Skip to content

Commit

Permalink
codec: expose Number of Bytes Read by the Decoder
Browse files Browse the repository at this point in the history
This allows users know where in the stream they are,
supporting consuming and truncating use-cases
e.g. given a byte slice, decode a user from it,
and return the remainder of the byte slice
to other module for further processing.

Fixes #241
Fixes #235
  • Loading branch information
ugorji committed Apr 7, 2018
1 parent b4c50a2 commit f3cacc1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions codec/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,10 @@ func (d *Decoder) wrapErrstr(v interface{}, err *error) {
*err = fmt.Errorf("%s decode error [pos %d]: %v", d.hh.Name(), d.r.numread(), v)
}

func (d *Decoder) NumBytesRead() int {
return d.r.numread()
}

// --------------------------------------------------

// decSliceHelper assists when decoding into a slice, from a map or an array in the stream.
Expand Down

0 comments on commit f3cacc1

Please sign in to comment.