//go:build go1.27 && goexperiment.jsonv2

package decoder

import (
	
	
	stdjsontext 
	stdjson 
	
	

	
)

// stdUnmarshalerFromType is the interface of UnmarshalJSONFrom with the Decoder of encoding/json/jsontext, which
// encoding/json calls where it is built on encoding/json/v2.
var stdUnmarshalerFromType = reflect.TypeFor[stdjson.UnmarshalerFrom]()

// stdFromDecoder is a decoder of encoding/json/jsontext which an UnmarshalJSONFrom method reads from, and the reader
// of its input.
type stdFromDecoder struct {
	r   bytes.Reader
	dec *stdjsontext.Decoder
}

var stdFromDecoders = sync.Pool{New: func() any {
	 := new(stdFromDecoder)
	.dec = stdjsontext.NewDecoder(&.r)
	return 
}}

// The options of the decoder which UnmarshalJSONFrom of encoding/json/jsontext reads from, as fromOptions: the ones
// of encoding/json, its DefaultOptionsV1, and with RejectUnknownMembers for DisallowUnknownFieldsOption. UseNumberOption
// has none: encoding/json gives its methods UseNumber by an option which it doesn't export ( see
// issues/decoder-std-unmarshal-from-use-number.md ).
var (
	stdFromOptions       = json.DefaultOptionsV1()
	stdFromRejectOptions = stdjson.JoinOptions(stdFromOptions, stdjson.RejectUnknownMembers(true))
)

// stdUnmarshalFrom calls UnmarshalJSONFrom of v, a stdjson.UnmarshalerFrom, with a decoder of the value, as
// unmarshalFrom does.
func stdUnmarshalFrom( any,  []byte,  OptionFlags) (bool, error) {
	 := stdFromDecoders.Get().(*stdFromDecoder)
	defer stdFromDecoders.Put()
	.r.Reset()
	 := stdFromOptions
	if &DisallowUnknownFieldsOption != 0 {
		 = stdFromRejectOptions
	}
	.dec.Reset(&.r, )
	 := .(stdjson.UnmarshalerFrom).UnmarshalJSONFrom(.dec)
	,  := .dec.StackIndex(0)
	,  := errors.MethodCallResult(, .dec.StackDepth(), )
	.r.Reset(nil)
	return , 
}