decode.go
func (d Decoder) Decode(v interface{}) error {
	to := reflect.ValueOf(v)

	if d.off != 0 {
		var err error
		if d.off, err = 0, d.Parser.ParseMapValue(d.off-1); err != nil {
			return err
		}
	}

	if !to.IsValid() {
		// This special case for a nil value is used to make it possible to
		// discard decoded values.
		_, err := d.decodeInterface(to)
		return err
	}

	// Optimization for ValueDecoder, in practice tho it's also handled in the
	// methods that are based on reflection.
	switch x := v.(type) {
	case ValueDecoder:
		return x.DecodeValue(d)
	}

	if to.Kind() == reflect.Ptr {
		// In most cases the method receives a pointer, but we may also have to
		// support types that aren't pointers but implement ValueDecoder, or
		// types that have got adapters set.
		// If we're not in either of those cases the code will likely panic when
		// the value is set because it won't be addressable.
		to = to.Elem()
	}

	_, err := d.decode(to)
	return err
}
func (d Decoder) Decode(v interface{}) error {
	to := reflect.ValueOf(v)

	if d.off != 0 {
		var err error
		if d.off, err = 0, d.Parser.ParseMapValue(d.off-1); err != nil {
			return err
		}
	}

	if !to.IsValid() {
		// This special case for a nil value is used to make it possible to
		// discard decoded values.
		_, err := d.decodeInterface(to)
		return err
	}

	// Optimization for ValueDecoder, in practice tho it's also handled in the
	// methods that are based on reflection.
	switch x := v.(type) {
	case ValueDecoder:
		return x.DecodeValue(d)
	}

	if to.Kind() == reflect.Ptr {
		// In most cases the method receives a pointer, but we may also have to
		// support types that aren't pointers but implement ValueDecoder, or
		// types that have got adapters set.
		// If we're not in either of those cases the code will likely panic when
		// the value is set because it won't be addressable.
		to = to.Elem()
	}

	_, err := d.decode(to)
	return err
}
// Decode expects v to be a pointer to a value in which the decoder will load
// the next parsed data.
//
// The method panics if v is neither a pointer type nor implements the
// ValueDecoder interface, or if v is a nil pointer.