github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/perf/json/decoder.go (about)

     1  package json
     2  
     3  import "io"
     4  
     5  // Decoder is a wrapper of encoding/json.Decoder.
     6  // It provides same methods as encoding/json.Decoder but with method
     7  // chaining capabilities.
     8  //
     9  // See encoding/json.Decoder for detailed document.
    10  type Decoder struct {
    11  	UnderlyingDecoder
    12  }
    13  
    14  // NewDecoder returns a new Decoder that reads from r.
    15  func NewDecoder(r io.Reader) *Decoder {
    16  	return &Decoder{getImpl().NewDecoder(r)}
    17  }
    18  
    19  // UseNumber causes the Decoder to unmarshal a number into an interface{}
    20  // as a Number instead of as a float64.
    21  func (dec *Decoder) UseNumber() *Decoder {
    22  	dec.UnderlyingDecoder.UseNumber()
    23  	return dec
    24  }
    25  
    26  // DisallowUnknownFields causes the Decoder to return an error when the
    27  // destination is a struct and the input contains object keys which do
    28  // not match any non-ignored, exported fields in the destination.
    29  func (dec *Decoder) DisallowUnknownFields() *Decoder {
    30  	dec.UnderlyingDecoder.DisallowUnknownFields()
    31  	return dec
    32  }