Jelajahi Sumber

codec: expose Number of Bytes Read by the Decoder

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
Ugorji Nwoke 7 tahun lalu
induk
melakukan
f3cacc17c8
1 mengubah file dengan 4 tambahan dan 0 penghapusan
  1. 4 0
      codec/decode.go

+ 4 - 0
codec/decode.go

@@ -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.