package decoder

import (
	
	
	
	stderrors 
	
	
	
	
	
	
	
	
	

	
	
	
)

// The decoders of the semantics of encoding/json/v2, which the v2 json package decodes by: a value is decoded by the
// decoder of v1 of its type where v2 decodes it as v1 does, and by a decoder of its own where v2 differs. The
// decoding stops at the first error. An error of a value is an errors.UnmarshalError, which skipTypeError returns
// instead of recording it, and which the decoders here make of the type errors which the decoders of v1 record
// ( see v2Error ). Any other error, as a syntax error, the v2 json package finds again in the input, as
// encoding/json/v2 reports it: the decoders here only find the text which v2 rejects and v1 decodes, the strings of
// invalid UTF-8 and the objects which have a name twice ( see errV2Text ).

var (
	// errV2Text is the error of the text of a value which v2 rejects: a string of invalid UTF-8, or an object which
	// has a name twice.
	errV2Text = stderrors.New("json: invalid text of encoding/json/v2")
	// errNilInterface is the error of a nil value of an interface type with methods, which no value can be
	// decoded into.
	errNilInterface = stderrors.New("cannot derive concrete type for nil interface with finite type set")
	// errV2DuplicateName is the error of an object of an interface{} which has a name twice, which
	// decodeNewStringAnyMap returns with the semantics of v2: they reject it, or decode the value of the name into
	// the value of its first one ( see v2InterfaceDecoder ).
	errV2DuplicateName = stderrors.New("json: duplicate name of encoding/json/v2")
	// errNoDefaultRepresentation is the error of a time.Duration, which v2 has no representation of without the
	// `format` option.
	errNoDefaultRepresentation = stderrors.New("no default representation")
	errArrayUnderflow          = stderrors.New("too few array elements")
	errArrayOverflow           = stderrors.New("too many array elements")
)

var timeDurationType = reflect.TypeOf(time.Duration(0))

// IsArrayLengthError reports whether err is the error of the length of a JSON array decoded into a Go array, which is
// at the end of the JSON array.
func ( error) bool {
	return  == errArrayOverflow ||  == errArrayUnderflow
}

// cachedV2Decoders are the decoders of v2, without and with StringifyNumbers.
var cachedV2Decoders [2]runtime.TypeCache[Decoder]

// v1DecoderOptions are the options of encoding/json which change the decoders of a type: a decoding with one of them
// takes its decoders from v1OptionDecoders, apart from the tables shared by every goroutine, which have no room for
// them, as few programs use them, and from the recent decoders of its context, which are the ones of its options
// ( see SetV2Flags ).
const v1DecoderOptions = V2CallMethodsWithLegacySemantics | V2FormatByteArrayAsArray |
	V2FormatBytesWithLegacySemantics | V2FormatDurationAsNano | V2ReportErrorsWithLegacySemantics |
	V2StringifyWithLegacySemantics

// flagsKey is what the decoders of a type for options are cached by in a sync.Map: the type, and the options of
// v1DecoderOptions, with V2StringifyNumbers: the decoders of the options of encoding/json ( see v1OptionDecoders ) and
// the ones of the functions of unmarshaling ( see UnmarshalFuncs ).
type flagsKey struct {
	typeptr uintptr
	flags   V2Flags
}

// v1OptionDecoders are the decoders of v2 of the options of encoding/json ( see v1DecoderOptions ).
var v1OptionDecoders sync.Map // map[flagsKey]Decoder

// decoderIn returns the decoder of the pointer type typ for the options flags from m, compiling it for the functions
// funcs, or none, if the type is new.
func decoderIn( *sync.Map,  unsafe.Pointer,  V2Flags,  *UnmarshalFuncs) (Decoder, error) {
	 := flagsKey{typeptr: uintptr(), flags:  & (v1DecoderOptions | V2StringifyNumbers)}
	if ,  := .Load();  {
		return .(Decoder), nil
	}
	 := newCompiler(true)
	.stringifyNumbers, .v1Options, .funcs = &V2StringifyNumbers != 0, &v1DecoderOptions, 
	,  := compileHead(runtime.TypeOfPtr(), )
	if  != nil {
		return nil, 
	}
	,  := .LoadOrStore(, )
	return .(Decoder), nil
}

// CompileToGetDecoderV2 returns the decoder of the type for the semantics of encoding/json/v2 and the options flags,
// of which StringifyNumbers and the ones of v1DecoderOptions change the decoders, compiling it if the type is new.
func ( unsafe.Pointer,  V2Flags) (Decoder, error) {
	if &v1DecoderOptions != 0 {
		return decoderIn(&v1OptionDecoders, , , nil)
	}
	 := &V2StringifyNumbers != 0
	 := &cachedV2Decoders[0]
	if  {
		 = &cachedV2Decoders[1]
	}
	 := uintptr()
	if  := .Load();  != nil {
		return *, nil
	}
	 := newCompiler(true)
	.stringifyNumbers = 
	,  := compileHead(runtime.TypeOfPtr(), )
	if  != nil {
		return nil, 
	}
	return *.Store(, &), nil
}

// The marks of the keys of the decoders of v2 among the recent decoders of a context ( see DecoderOfV2 ), in the two
// lowest bits of the address of the type, which are 0, as a type is aligned to 4 bytes at least: v2DecoderMark for a
// decoder of v2, which is not the decoder of v1 of the type, and stringifyDecoderMark for one with StringifyNumbers
// too, which is another again.
const (
	v2DecoderMark        = 1
	stringifyDecoderMark = 2
)

// DecoderOfV2 returns the decoder of the semantics of encoding/json/v2 of the type, for the options and the
// functions of unmarshaling of ctx. The decoder of a call without functions is remembered with the decoders of the
// context as v1's DecoderOf remembers them, under the address of the type with the marks of the decoders of v2. A
// decoder in neither entry of its set is the one of the shared table, which takes the first entry, and the one decoded
// before it the second.
func ( *RuntimeContext) ( unsafe.Pointer) (Decoder, error) {
	if  := .v2Funcs();  != nil {
		return .decoderOf(, .Option.V2)
	}
	 := .Option.V2
	if .recentDecoders == nil {
		return CompileToGetDecoderV2(, )
	}
	 := uintptr() | v2DecoderMark
	if &V2StringifyNumbers != 0 {
		 |= stringifyDecoderMark
	}
	 := &.recentDecoders[(uint64()*runtime.TypeHashMultiplier)>>recentDecoderHashShift]
	if [0].typeptr ==  {
		return [0].dec, nil
	}
	if [1].typeptr ==  {
		return [1].dec, nil
	}
	,  := CompileToGetDecoderV2(, )
	if  != nil {
		return nil, 
	}
	.keep(, )
	return , nil
}

// SetV2Flags sets the options of v2 of ctx for a decoding, which every setting of them before a decoding is made by, as
// the others clear them after one: the recent decoders are emptied if they were compiled for other options of
// encoding/json which change the decoders, which their keys have no room for ( see recentV1Options ), once for the call
// rather than in every DecoderOfV2, by a call of its own, so that SetV2Flags is inlined into the callers.
func ( *RuntimeContext,  V2Flags) {
	.Option.V2 = 
	if  :=  & v1DecoderOptions;  != .recentV1Options {
		emptyRecentDecoders(, )
	}
}

// emptyRecentDecoders empties the recent decoders of ctx, if it has them, which are compiled for the options
// v1Options of encoding/json from now on.
func emptyRecentDecoders( *RuntimeContext,  V2Flags) {
	if .recentDecoders != nil {
		*.recentDecoders = [recentDecoderSets]recentDecoderSet{}
	}
	.recentV1Options = 
}

// compileV2 returns the decoder of a value of typ by the semantics of v2.
func ( *compiler) ( reflect.Type, ,  string) (Decoder, error) {
	if ,  := .decoders[uintptr(runtime.TypePtr())];  {
		return , nil
	}
	// the first method which decodes a value: with CallMethodsWithLegacySemantics, a key of a map is decoded by
	// UnmarshalText or its kind, as encoding/json doesn't call UnmarshalJSONFrom and UnmarshalJSON for a key
	 := methodUnmarshalJSONFrom
	if .mapKeys && .v1Options&V2CallMethodsWithLegacySemantics != 0 {
		 = methodUnmarshalText
	}
	if  := .funcs.funcsOf(); len() > 0 {
		 := &v2FuncDecoder{typ: , funcs: }
		return , .compileNextV2(, &.next, , , , )
	}
	return .compileDefaultV2(, , , )
}

// compileNextV2 compiles into next the decoder of typ which dec leaves a value to, by the methods of typ from first
// on, or by its kind ( see compileDefaultV2 ): dec stays the decoder of typ in c.decoders, so that the values of typ
// within the value are decoded by it too. Only a type which may have values of itself is put there: a decoder of a
// kind of v1 looks itself up there ( see compileKind ).
func ( *compiler) ( Decoder,  *Decoder,  reflect.Type,  int, ,  string) error {
	 := uintptr(runtime.TypePtr())
	switch .Kind() {
	case reflect.Struct, reflect.Map, reflect.Slice, reflect.Array, reflect.Pointer:
		if ,  := .decoders[]; ! {
			.decoders[] = 
		}
	}
	,  := .compileDefaultV2(, , , )
	* = 
	return 
}

// compileDefaultV2 returns the decoder of a value of typ without the functions of unmarshaling: by the time types,
// by the first of its methods of unmarshaling from first on, or by its kind. A method which may decline a value
// leaves it to the decoder of the methods after it.
func ( *compiler) ( reflect.Type,  int, ,  string) (Decoder, error) {
	switch {
	case  == timeDurationType && .v1Options&V2FormatDurationAsNano == 0:
		// a time.Duration has no representation, but its nanoseconds as an int64 with FormatDurationAsNano, which
		// its kind gives
		return &v2InvalidDecoder{typ: , err: errNoDefaultRepresentation}, nil
	case  == timeType:
		if .stringTag {
			return &v2InvalidDecoder{typ: , err: errInvalidStringTag}, nil
		}
		return v2TimeDecoder{}, nil
	}
	switch v2MethodOf(, ) {
	case methodUnmarshalJSONFrom:
		 := &v2UnmarshalFromDecoder{typ: }
		return , .compileNextV2(, &.next, , methodUnmarshalJSON, , )
	case methodUnmarshalJSON:
		return &v2UnmarshalJSONDecoder{typ: , ptrType: runtime.TypePtr(reflect.PointerTo())}, nil
	case methodUnmarshalText:
		return &v2UnmarshalTextDecoder{typ: , ptrType: runtime.TypePtr(reflect.PointerTo()), zero: newZeroer()}, nil
	}
	 := .stringTag && .v1Options&V2StringifyWithLegacySemantics != 0
	if .stringTag && .Kind() != reflect.Ptr && !isNumberKind(.Kind()) && !hasNoRepresentation(.Kind()) {
		if  &&  != jsonNumberType && (.Kind() == reflect.Bool || .Kind() == reflect.String) {
			// the option applies to a bool and a string too with StringifyWithLegacySemantics
			return &v2StringifiedDecoder{typ: }, nil
		}
		// the option applies to a number, through pointers
		return &v2InvalidDecoder{typ: , err: errInvalidStringTag}, nil
	}
	switch  := .Kind();  {
	case reflect.Ptr:
		if  {
			return .compileStringifiedPtrV2(, , )
		}
		return compilePtr(, , , )
	case reflect.Slice:
		if IsV2Bytes(, .v1Options) {
			return .compileBytesV2(, , )
		}
		return compileSlice(, , , )
	case reflect.Array:
		if IsV2Bytes(, .v1Options) {
			return .compileBytesV2(, , )
		}
		return .compileArrayV2(, , )
	case reflect.Interface:
		return .newV2InterfaceDecoder(), nil
	case reflect.String:
		 := newStringDecoder(, )
		.typ = 
		return v2StringDecoder{}, nil
	case reflect.Bool,
		reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
		reflect.Float32, reflect.Float64:
		if .stringifyNumbers &&  != reflect.Bool {
			return newV2StringNumberDecoder(), nil
		}
		// the decoder of v1, which decodes null as the zero value and returns a type error by the semantics of v2
		// ( see numberError )
		return compileKind(, , , )
	case reflect.Struct:
		return .compileStructV2()
	case reflect.Map:
		return .compileMapV2(, , )
	}
	// a complex number, a channel, a function or an unsafe.Pointer, which has no representation, whatever the options
	// are ( see hasNoRepresentation )
	return &v2InvalidDecoder{typ: }, nil
}

// hasNoRepresentation reports whether a value of the kind has no JSON representation: a complex number, a channel, a
// function or an unsafe.Pointer.
func hasNoRepresentation( reflect.Kind) bool {
	switch  {
	case reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func, reflect.UnsafePointer:
		return true
	}
	return false
}

// IsV2Bytes reports whether typ, a slice or an array, is of bytes for the options flags, whose value is a base64
// string: a []byte or a [N]byte, but a [N]byte with FormatByteArrayAsArray, and a slice or an array of a named byte
// type with FormatBytesWithLegacySemantics, which is otherwise a JSON array of its values.
func ( reflect.Type,  V2Flags) bool {
	 := .Elem()
	if .Kind() != reflect.Uint8 || .Kind() == reflect.Array && &V2FormatByteArrayAsArray != 0 {
		return false
	}
	return .PkgPath() == "" || &V2FormatBytesWithLegacySemantics != 0
}

// compileBytesV2 returns the decoder of typ, a slice or an array of bytes ( see IsV2Bytes ), which a JSON array is
// decoded into element by element with FormatBytesWithLegacySemantics, as into any other slice or array.
func ( *compiler) ( reflect.Type, ,  string) (Decoder, error) {
	 := newV2BytesDecoder()
	if .v1Options&V2FormatBytesWithLegacySemantics == 0 {
		return , nil
	}
	var  Decoder
	var  error
	if .Kind() == reflect.Slice {
		,  = compileSlice(, , , )
	} else {
		,  = .compileArrayV2(, , )
	}
	if  != nil {
		return nil, 
	}
	return &v2FormatBytesWithLegacySemanticsDecoder{bytes: , elements: }, nil
}

// V2TypeError returns the type error which a decoder of v1 recorded, as the error of v2 ( see v2Error ), or nil if
// none did.
func ( *RuntimeContext) () error {
	if .typeError == nil {
		return nil
	}
	return .v2Error()
}

// v2Error returns the type error which a decoder of v1 recorded, as the error of v2, which stops the decoding: the
// error of a number which is not a value of its type reports the number. The type error is cleared.
func ( *RuntimeContext) () error {
	 := .typeError
	.typeError = nil
	if .plain != nil {
		return .plain
	}
	 := &errors.UnmarshalError{GoType: .typ, Start: .start, End: .end, Err: .err}
	if .literal {
		.HasValue = true
		.Err = numberCause(.Buf[.start:.end], .typ)
	}
	return 
}

// numberCause returns the cause of the error of the number num, which is not a value of typ, as strconv returns it:
// strconv.ErrSyntax for a number which is not an integer, or negative, of an integer type, and strconv.ErrRange for a
// number out of the range of the type.
func numberCause( []byte,  reflect.Type) error {
	switch .Kind() {
	case reflect.Float32, reflect.Float64:
		return strconv.ErrRange
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		if [0] == '-' {
			return strconv.ErrSyntax
		}
	}
	if bytes.ContainsAny(, ".eE") {
		return strconv.ErrSyntax
	}
	return strconv.ErrRange
}

// validV2Text reports whether the strings of text, a JSON text valid by the grammar, have the text which v2 allows:
// valid UTF-8, and no escape of a surrogate which is not a pair.
func validV2Text( []byte) bool {
	return utf8.Valid() && !hasLoneSurrogate()
}

// hasLoneSurrogate reports whether the escapes of b, a part of a JSON text valid by the grammar, have a surrogate
// which is not a pair: a high surrogate which no low surrogate follows, or a low surrogate which no high surrogate
// precedes.
func hasLoneSurrogate( []byte) bool {
	for {
		// a backslash is in a string only, where it starts an escape; an escape of \u has six bytes.
		 := bytes.IndexByte(, '\\')
		if  < 0 {
			return false
		}
		if [+1] != 'u' {
			 = [+2:]
			continue
		}
		 := hexValue([+2 : +6])
		 = [+6:]
		switch {
		case  >= 0xdc00 &&  < 0xe000:
			return true
		case  >= 0xd800 &&  < 0xdc00:
			if len() < 6 || [0] != '\\' || [1] != 'u' {
				return true
			}
			if  := hexValue([2:6]);  < 0xdc00 ||  >= 0xe000 {
				return true
			}
			 = [6:]
		}
	}
}

// hexValue returns the number of the four hexadecimal digits of b.
func hexValue( []byte) rune {
	var  rune
	for ,  := range  {
		switch {
		case  <= '9':
			 -= '0'
		case  <= 'F':
			 -= 'A' - 10
		default:
			 -= 'a' - 10
		}
		 = <<4 | rune()
	}
	return 
}

// isNumberKind reports whether a value of the kind is a JSON number.
func isNumberKind( reflect.Kind) bool {
	switch  {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
		reflect.Float32, reflect.Float64:
		return true
	}
	return false
}

// v2StringDecoder is the decoder of a string of v2: null is "", and a string must be valid UTF-8, without an escape
// of a surrogate which is not a pair, unless V2AllowInvalidUTF8 ( see decodeStringV2 ).
type v2StringDecoder struct{ *stringDecoder }

func ( v2StringDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	var (
		    string
		 int64
		  error
	)
	 := .Buf
	 := skipWhiteSpace(, )
	if [] == '"' {
		, ,  = decodeStringV2(.stringDecoder, , +1)
	} else {
		var  bool
		if , , ,  = .decodeStringValue(, );  == nil &&  {
			 = replacedRuneError(, , , )
		} else if  == nil && [] == 'n' && .Option.V2&V2MergeWithLegacySemantics != 0 {
			// null, which leaves the string as it is with MergeWithLegacySemantics
			return , nil
		}
	}
	if  != nil {
		return 0, 
	}
	**(**string)(unsafe.Pointer(&)) = 
	return , nil
}

// decodeStringV2 decodes the string whose bytes start at start, after its quote, as decodeStringField decodes it, for
// a string of v2. A string of bytes which are not control characters and of escapes which are not \u, whose words are
// read as decodeStringField reads them, is decoded here if its bytes are valid UTF-8, which the loops here look
// for: it has no text which v2 rejects. Any other string is decoded by decodeStringField, whose errors are the ones
// of the string, and which replaces invalid UTF-8 and an escape of a surrogate which is not a pair by U+FFFD, which
// is an error unless the input has it ( see replacedRuneError ). So is a string which goes on past the words read
// where the CPU has a SIMD scan.
func decodeStringV2( *stringDecoder,  *RuntimeContext,  int64) (string, int64, error) {
	 := .Buf
	 := (*sliceHeader)(unsafe.Pointer(&)).data
	 := int64(len())
	 := 
	 := 
	if hasStringSIMD {
		 = min(, +64)
	}
	// The words of a plain ASCII string, which most are, are looked at by this loop, which keeps nothing else, as
	// the first loop of decodeStringField.
	for +8 <=  {
		 := load64(, )
		if  := keyEndBytes() | &msb;  != 0 {
			 += int64(bits.TrailingZeros64() / 8)
			if char(, ) == '"' {
				return .makeString([:]),  + 1, nil
			}
			break
		}
		 += 8
	}
	 := int64(-1)
	 := false
	// ascii are the top bits which stop the words at a byte which is not ASCII, until the first one is met.
	 := uint64(msb)
	for {
		 := char(, )
		switch {
		case  == '"':
			,  := [:], +1
			if  && !utf8.Valid() {
				return decodeStringV1(, , )
			}
			if  < 0 {
				return .makeString(), , nil
			}
			// the literal is valid UTF-8, and has no \u escape, so its decoding is valid UTF-8 too: it is not
			// validated again
			return .unescapeString(, stringInfo{firstEscape: int()}), , nil
		case  == '\\':
			switch char(, +1) {
			case '"', '\\', '/', 'b', 'f', 'n', 'r', 't':
				if  < 0 {
					 =  - 
				}
				 += 2
			default:
				// an escape \u, or an invalid one
				return decodeStringV1(, , )
			}
		case  >= 0x80:
			,  = true, 0
			++
		case  >= 0x20 &&  == :
			// the words stopped where they may not be read, near the end of the buffer, not at a byte to look at
			++
		default:
			// a control character, the end of the input, or the end of the words where the CPU has a SIMD scan
			return decodeStringV1(, , )
		}
		for +8 <=  {
			 := load64(, )
			if  := keyEndBytes() | &;  != 0 {
				 += int64(bits.TrailingZeros64() / 8)
				break
			}
			 += 8
		}
	}
}

// decodeStringV1 decodes the string whose bytes start at start, after its quote, by decodeStringField, which replaces
// invalid UTF-8 and an escape of a surrogate which is not a pair by U+FFFD, which is an error ( see
// replacedRuneError ).
func decodeStringV1( *stringDecoder,  *RuntimeContext,  int64) (string, int64, error) {
	, , ,  := .decodeStringField(, )
	if  != nil {
		return "", 0, 
	}
	if  := replacedRuneError(, , -1, );  != nil {
		return "", 0, 
	}
	return , , nil
}

// replacedRuneError returns errV2Text if the string s, which the decoders of v1 decoded from the string from start up
// to next in the input, has a U+FFFD which they made of invalid UTF-8 or of an escape of a surrogate which is not a
// pair, unless V2AllowInvalidUTF8, and nil otherwise. A U+FFFD of the input is valid.
func replacedRuneError( *RuntimeContext,  string, ,  int64) error {
	if .Option.V2&V2AllowInvalidUTF8 == 0 && strings.IndexByte(, 0xef) >= 0 && !validV2Text(.Buf[:]) {
		return errV2Text
	}
	return nil
}

// v2StringNumberDecoder is the decoder of a number of v2 with StringifyNumbers: the number is in a JSON string, by
// the grammar of the JSON numbers, and null is its zero value.
type v2StringNumberDecoder struct {
	typ  reflect.Type
	kind reflect.Kind
	str  *stringDecoder
}

func newV2StringNumberDecoder( reflect.Type) *v2StringNumberDecoder {
	return &v2StringNumberDecoder{typ: , kind: .Kind(), str: newStringDecoder("", "")}
}

func ( *v2StringNumberDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	switch [] {
	case 'n':
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if .Option.V2&V2MergeWithLegacySemantics == 0 {
			clear(unsafe.Slice((*byte)(), .typ.Size()))
		}
		return  + 4, nil
	case '"':
	default:
		return .skipTypeError(, , .typ)
	}
	, ,  := .str.decodeByte(, )
	if  != nil {
		return 0, 
	}
	// with StringifyWithLegacySemantics, the number is read by the syntax of Go numbers, of which the JSON numbers are
	// a part, and a quoted null is null, as v1 reads them: the option is looked at for a number of no JSON number only
	if !jsonnum.IsValid() && .Option.V2&V2StringifyWithLegacySemantics == 0 {
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , End: , HasValue: true, Err: strconv.ErrSyntax}
	}
	if  := setNumber(, .kind, );  != nil {
		if .Option.V2&V2StringifyWithLegacySemantics != 0 && string() == "null" {
			if .Option.V2&V2MergeWithLegacySemantics == 0 {
				clear(unsafe.Slice((*byte)(), .typ.Size()))
			}
			return , nil
		}
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , End: , HasValue: true, Err: }
	}
	return , nil
}

// v2StringifiedDecoder is the decoder of a bool or a string of a field of the `string` option with
// StringifyWithLegacySemantics: the JSON string "true" or "false" of a bool, and the JSON string of a JSON string of a
// string. null and the JSON string "null" are the zero value.
type v2StringifiedDecoder struct {
	typ reflect.Type
}

func ( *v2StringifiedDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	switch [] {
	case 'n':
		if  := validateNull(, );  != nil {
			return 0, 
		}
		.zero(, )
		return  + 4, nil
	case '"':
	default:
		return .skipTypeError(, , .typ)
	}
	var  string
	,  := v2StringDecoder{skipStringDecoder}.Decode(, , , unsafe.Pointer(&))
	if  != nil {
		return 0, 
	}
	switch {
	case  == "null":
		.zero(, )
	case .typ.Kind() == reflect.Bool && ( == "true" ||  == "false"):
		*(*bool)() =  == "true"
	case .typ.Kind() == reflect.Bool:
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , End: , HasValue: true, Err: strconv.ErrSyntax}
	default:
		,  := V2Hooks.AppendUnquote(nil, )
		if  != nil {
			return 0, &errors.UnmarshalError{GoType: .typ, Start: , Err: }
		}
		*(*string)() = string()
	}
	return , nil
}

// zero sets the bool or the string at p to its zero value for null, but with MergeWithLegacySemantics.
func ( *v2StringifiedDecoder) ( *RuntimeContext,  unsafe.Pointer) {
	if .Option.V2&V2MergeWithLegacySemantics != 0 {
		return
	}
	if .typ.Kind() == reflect.Bool {
		*(*bool)() = false
	} else {
		*(*string)() = ""
	}
}

func ( *v2StringifiedDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// compileStringifiedPtrV2 returns the decoder of a pointer of a field of the `string` option with
// StringifyWithLegacySemantics ( see v2StringifiedPtrDecoder ).
func ( *compiler) ( reflect.Type, ,  string) (Decoder, error) {
	 := &v2StringifiedPtrDecoder{}
	if .Elem().Kind() == reflect.Ptr {
		// the option applies to one pointer only: a pointer to a pointer is its error, before the value is read
		.ptr = &v2InvalidDecoder{typ: , err: errInvalidStringTag}
		return , nil
	}
	var  error
	.ptr,  = compilePtr(, , , )
	return , 
}

// v2StringifiedPtrDecoder is the decoder of a pointer of a field of the `string` option with
// StringifyWithLegacySemantics: null is nil, and any other value is decoded by ptr, the decoder of the pointer, after
// which the JSON string "null" sets the pointer nil, as encoding/json/v2 sets it after the value it points to is
// decoded. A pointer to a pointer is the error of the option, of ptr.
type v2StringifiedPtrDecoder struct {
	ptr Decoder
}

func ( *v2StringifiedPtrDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	if [] == 'n' {
		if  := validateNull(, );  != nil {
			return 0, 
		}
		*(*unsafe.Pointer)() = nil
		return  + 4, nil
	}
	,  := .ptr.Decode(, , , )
	if  != nil {
		return 0, 
	}
	// the JSON string "null", also of escapes, unlike encoding/json/v2, which tells it by the value as the input has
	// it only
	if  := [:]; string() == `"null"` || [0] == '"' && bytes.IndexByte(, '\\') >= 0 && .isNull(, , ) {
		*(*unsafe.Pointer)() = nil
	}
	return , nil
}

// isNull reports whether the JSON string at cursor, of escapes, is "null".
func ( *v2StringifiedPtrDecoder) ( *RuntimeContext, ,  int64) bool {
	var  string
	,  := v2StringDecoder{skipStringDecoder}.Decode(, , , unsafe.Pointer(&))
	return  == nil &&  == "null"
}

func ( *v2StringifiedPtrDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

func ( *v2StringNumberDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// setNumber sets the number at p, of the numeric kind, to num, a JSON number, and returns the cause of the error of
// a number which is not a value of the kind, as strconv returns it, which leaves the value as it is.
func setNumber( unsafe.Pointer,  reflect.Kind,  []byte) error {
	 := unsafe.String(unsafe.SliceData(), len())
	var  error
	switch  {
	case reflect.Float32, reflect.Float64:
		 := 64
		if  == reflect.Float32 {
			 = 32
		}
		var  float64
		if ,  = strconv.ParseFloat(, );  == nil {
			if  == reflect.Float32 {
				*(*float32)() = float32()
			} else {
				*(*float64)() = 
			}
		}
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		var  int64
		if ,  = strconv.ParseInt(, 10, intBits());  == nil {
			switch  {
			case reflect.Int:
				*(*int)() = int()
			case reflect.Int8:
				*(*int8)() = int8()
			case reflect.Int16:
				*(*int16)() = int16()
			case reflect.Int32:
				*(*int32)() = int32()
			default:
				*(*int64)() = 
			}
		}
	default:
		var  uint64
		if ,  = strconv.ParseUint(, 10, intBits());  == nil {
			switch  {
			case reflect.Uint:
				*(*uint)() = uint()
			case reflect.Uint8:
				*(*uint8)() = uint8()
			case reflect.Uint16:
				*(*uint16)() = uint16()
			case reflect.Uint32:
				*(*uint32)() = uint32()
			case reflect.Uintptr:
				*(*uintptr)() = uintptr()
			default:
				*(*uint64)() = 
			}
		}
	}
	if  != nil {
		return stderrors.Unwrap()
	}
	return nil
}

// intBits returns the bits of an integer of the kind.
func intBits( reflect.Kind) int {
	switch  {
	case reflect.Int8, reflect.Uint8:
		return 8
	case reflect.Int16, reflect.Uint16:
		return 16
	case reflect.Int32, reflect.Uint32:
		return 32
	case reflect.Int, reflect.Uint, reflect.Uintptr:
		return strconv.IntSize
	}
	return 64
}

// v2InvalidDecoder is the decoder of a type which no JSON value is decoded into by v2, null included: its error,
// whose cause is err, is the one of the type, before the value is read. err is nil for a type which has no
// representation ( see hasNoRepresentation ), which fails after its value with ReportErrorsWithLegacySemantics, as
// encoding/json reads it, but for null, which is decoded into nothing.
type v2InvalidDecoder struct {
	typ reflect.Type
	err error
}

func ( *v2InvalidDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 = skipWhiteSpace(.Buf, )
	if .err == nil && .Option.V2&V2ReportErrorsWithLegacySemantics != 0 {
		if .Buf[] == 'n' {
			return  + 4, validateNull(.Buf, )
		}
		return 0, &errors.UnmarshalError{GoType: .typ, Start: }
	}
	return 0, &errors.UnmarshalError{GoType: .typ, Start: , NoKind: true, Err: .err}
}

func ( *v2InvalidDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// zeroer sets a value of a type to its zero value.
type zeroer struct {
	ptrType unsafe.Pointer
	size    uintptr
	// pointers is whether the type has pointers, whose zero value is set with the write barriers of the GC.
	pointers bool
}

func newZeroer( reflect.Type) zeroer {
	return zeroer{ptrType: ptrTypeOf(), size: .Size(), pointers: hasPointers()}
}

func ( zeroer) ( unsafe.Pointer) {
	if .pointers {
		valueAt(.ptrType, ).SetZero()
		return
	}
	clear(unsafe.Slice((*byte)(), .size))
}

// hasPointers reports whether a value of typ has a pointer.
func hasPointers( reflect.Type) bool {
	switch .Kind() {
	case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
		reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
		return false
	case reflect.Array:
		return .Len() > 0 && (.Elem())
	case reflect.Struct:
		for  := range .NumField() {
			if (.Field().Type) {
				return true
			}
		}
		return false
	}
	return true
}

// mergesInto reports whether a value of typ is decoded by v2 into the value it has, which a value of v2 must not be
// when it is an element of a slice: a pointer, which is decoded into what it points to, a value of an interface,
// a slice, a map, a struct, or an array of them.
func mergesInto( reflect.Type) bool {
	switch .Kind() {
	case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map, reflect.Struct:
		return true
	case reflect.Array:
		return (.Elem())
	}
	return false
}

// v2SliceDecoder is the decoder of a slice of v2: the elements are decoded as sliceDecoder decodes them, into the
// array of the slice, whose elements are set to their zero values before, as v2 decodes an element into its zero
// value. An element which the decoding overwrites anyway, as a number or a string is, is not set.
type v2SliceDecoder struct {
	*sliceDecoder
	zero bool
}

func newV2SliceDecoder( *sliceDecoder) *v2SliceDecoder {
	return &v2SliceDecoder{sliceDecoder: , zero: mergesInto(.elemType)}
}

func ( *v2SliceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 = skipWhiteSpace(.Buf, )
	if .zero && .Buf[] == '[' && (*sliceHeader)().cap > 0 && .Option.V2&V2MergeWithLegacySemantics == 0 {
		 := valueAt(.slicePtrType, )
		.Slice(0, .Cap()).Clear()
	}
	return .sliceDecoder.Decode(, , , )
}

// compileArrayV2 returns the decoder of the array type typ, which is not of bytes.
func ( *compiler) ( reflect.Type, ,  string) (Decoder, error) {
	 := &v2ArrayDecoder{typ: , array: newZeroer(), elem: newZeroer(.Elem()), alen: .Len()}
	,  := compileElem(, , , , )
	if  != nil {
		return nil, 
	}
	.valueDecoder = .goOnDecoder()
	return , nil
}

// v2ArrayDecoder is the decoder of an array of v2: an element is decoded into its zero value, and the JSON array
// must have as many elements as the array. null is the zero value.
type v2ArrayDecoder struct {
	typ          reflect.Type
	valueDecoder Decoder
	// array and elem set the array and an element to their zero values.
	array zeroer
	elem  zeroer
	alen  int
}

func ( *v2ArrayDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	switch [] {
	case 'n':
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if .Option.V2&V2MergeWithLegacySemantics == 0 {
			.array.zero()
		}
		return  + 4, nil
	case '[':
	default:
		return .skipTypeError(, , .typ)
	}
	++
	if  > maxDecodeNestingDepth {
		return 0, errors.ErrExceededMaxDepth([], )
	}
	 = skipWhiteSpace(, +1)
	 := 0
	var  error
	// an element is decoded into its zero value, but into the element with MergeWithLegacySemantics
	 := .Option.V2&V2MergeWithLegacySemantics == 0
	if [] != ']' {
		for {
			if  < .alen {
				 := unsafe.Add(, uintptr()*.elem.size)
				if  {
					.elem.zero()
				}
				,  := .valueDecoder.Decode(, , , )
				if  != nil {
					return 0, 
				}
				 = 
			} else {
				// an element past the length is a value of the input, checked as the options of the call say, as
				// the array fails at its end without UnmarshalArrayFromAnyLength
				,  := .skipValueV2(, )
				if  != nil {
					return 0, 
				}
				 = 
				 = errArrayOverflow
			}
			++
			 = skipWhiteSpace(, )
			if [] == ']' {
				break
			}
			if [] != ',' {
				return 0, errors.ErrInvalidCharacter([], "array", )
			}
			 = skipWhiteSpace(, +1)
		}
	}
	for ;  < .alen; ++ {
		.elem.zero(unsafe.Add(, uintptr()*.elem.size))
		 = errArrayUnderflow
	}
	if  != nil && .Option.V2&V2UnmarshalArrayFromAnyLength == 0 {
		// the error of the length is at the end of the array, which tells it
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , Err: }
	}
	return  + 1, nil
}

func ( *v2ArrayDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// v2BytesDecoder is the decoder of a []byte or a [N]byte of v2, whose bytes are a base64 string, by the standard
// encoding with padding: the array of a []byte is reused, and the bytes of a [N]byte must be N. null is the zero
// value.
type v2BytesDecoder struct {
	typ reflect.Type
	// alen is the length of a [N]byte, or -1 for a []byte.
	alen int
	str  *stringDecoder
}

func newV2BytesDecoder( reflect.Type) *v2BytesDecoder {
	 := &v2BytesDecoder{typ: , alen: -1, str: newStringDecoder("", "")}
	if .Kind() == reflect.Array {
		.alen = .Len()
	}
	return 
}

func ( *v2BytesDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	 := 
	switch [] {
	case 'n':
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if .alen < 0 {
			*(*[]byte)() = nil
		} else if .Option.V2&V2MergeWithLegacySemantics == 0 {
			clear(unsafe.Slice((*byte)(), .alen))
		}
		return  + 4, nil
	case '"':
	default:
		return .skipTypeError(, , .typ)
	}
	, ,  := .str.decodeByte(, )
	if  != nil {
		return 0, 
	}
	var  []byte
	if .alen < 0 {
		 = (*(*[]byte)())[:0]
	} else {
		 = unsafe.Slice((*byte)(), .alen)[:0]
	}
	,  := base64.StdEncoding.AppendDecode(, )
	if  == nil && len() != base64.StdEncoding.EncodedLen(len()) && .Option.V2&V2ParseBytesWithLooseRFC4648 == 0 {
		// the decoding skips a line feed and a carriage return, which RFC 4648 doesn't allow, unless
		// ParseBytesWithLooseRFC4648
		 := bytes.IndexAny(, "\r\n")
		 = fmt.Errorf("illegal character %s at offset %d", strconv.QuoteRune(rune([])), )
	}
	if  == nil && .alen >= 0 {
		 = [:.alen]
		clear([copy(, ):])
		if len() != .alen && .Option.V2&V2UnmarshalArrayFromAnyLength == 0 {
			 = fmt.Errorf("decoded length of %d mismatches array length of %d", len(), .alen)
		}
	}
	if  != nil {
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , Err: }
	}
	if .alen < 0 {
		if  == nil {
			 = []byte{}
		}
		*(*[]byte)() = 
	}
	return , nil
}

func ( *v2BytesDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// v2FormatBytesWithLegacySemanticsDecoder is the decoder of a slice or an array of bytes with
// FormatBytesWithLegacySemantics: a JSON array is decoded by the decoder of its elements, and any other value as bytes.
type v2FormatBytesWithLegacySemanticsDecoder struct {
	bytes    *v2BytesDecoder
	elements Decoder
}

func ( *v2FormatBytesWithLegacySemanticsDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	if .Buf[skipWhiteSpace(.Buf, )] == '[' {
		return .elements.Decode(, , , )
	}
	return .bytes.Decode(, , , )
}

func ( *v2FormatBytesWithLegacySemanticsDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

var anySliceType = reflect.TypeOf([]any(nil))

// v2InterfaceDecoder is the decoder of an interface value of v2. null sets it to nil. A nil value of an interface type
// without methods is set to the value of the JSON value, decoded as v1 decodes it, and a nil value of an interface type
// with methods can't be decoded into. A value which an interface value holds is decoded into: a copy of it is
// decoded by its own decoder, which the interface value is set to, but a map[string]interface{}, which an object is
// merged into, and a []interface{} ( see decodeMerging ).
type v2InterfaceDecoder struct {
	typ     reflect.Type
	ptrType unsafe.Pointer
	empty   bool
	fast    *interfaceDecoder
	// fromAny is whether a function of unmarshaling takes an interface{} or a type of the values of a nil
	// interface{}: a value is then decoded by the decoders of the functions, as a value of its type ( see
	// decodeByKind ), and never by decodeMerging, which calls no function.
	fromAny bool
}

// anyValueTypes are the types of the values of a nil interface{}, by the first byte of the JSON value.
var anyValueTypes = func() [256]reflect.Type {
	var  [256]reflect.Type
	['t'], ['f'] = boolType, boolType
	['"'] = stringType
	['-'] = float64Type
	for  := '0';  <= '9'; ++ {
		[] = float64Type
	}
	['{'] = interfaceMapType
	['['] = anySliceType
	return 
}()

var boolType = reflect.TypeOf(false)

func ( *compiler) ( reflect.Type) *v2InterfaceDecoder {
	 := &v2InterfaceDecoder{
		typ: , ptrType: ptrTypeOf(), empty: .NumMethod() == 0, fast: newEmptyInterfaceDecoder("", ""),
	}
	for ,  := range []reflect.Type{emptyInterfaceType, boolType, stringType, float64Type, interfaceMapType, anySliceType} {
		.fromAny = .fromAny || len(.funcs.funcsOf()) > 0
	}
	return 
}

func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	if (*[2]unsafe.Pointer)()[0] != nil && .Option.V2&V2MergeWithLegacySemantics != 0 {
		if !.holdsPointer() {
			*(*[2]unsafe.Pointer)() = [2]unsafe.Pointer{}
		} else if [] == 'n' && runtime.TypeOfPtr(heldType(, .empty)).Elem().Kind() == reflect.Pointer {
			// null into a pointer to a pointer, which sets the pointer it points to nil, rather than the interface
			// value
			if  := validateNull(, );  != nil {
				return 0, 
			}
			*(*unsafe.Pointer)(*interfaceData()) = nil
			return  + 4, nil
		}
	}
	if [] == 'n' {
		if  := validateNull(, );  != nil {
			return 0, 
		}
		*(*[2]unsafe.Pointer)() = [2]unsafe.Pointer{}
		return  + 4, nil
	}
	// the first word of an interface value is its type, or its itab, which is nil for a nil value
	if (*[2]unsafe.Pointer)()[0] != nil {
		return .decodeHeld(, , , )
	}
	if !.empty {
		return 0, &errors.UnmarshalError{GoType: .typ, Start: , NoKind: true, Err: errNilInterface}
	}
	if .fromAny {
		return .decodeByKind(, , , )
	}
	,  := .fast.decodeEmptyInterface(, , , )
	// with ReportErrorsWithLegacySemantics, the type error may be the one of a value before, which the decoding went
	// on after, which doesn't make the value decoded again and is kept
	 := .Option.V2&V2ReportErrorsWithLegacySemantics != 0
	if ( != nil || .typeError != nil && !) && .Option.V2&V2AllowDuplicateNames != 0 {
		if  := [];  == '{' ||  == '[' {
			// The value may have a name twice, whose second value is decoded into the first one, which v1 doesn't
			// do, and whose error may come before the one v1 found: the value is decoded again, by the merging of
			// v2, which meets its errors in the order of the input. The error which v1 recorded in the value, at
			// it or after it, is dropped; the one of a value before, with ReportErrorsWithLegacySemantics, is kept.
			if  := .typeError;  != nil && .start >=  {
				.typeError = nil
			}
			*(*[2]unsafe.Pointer)() = [2]unsafe.Pointer{}
			return .decodeMerging(, , , )
		}
	}
	if .typeError != nil && ! {
		// a number out of the range of a float64, which v1 records and decodes on from: it comes before any other
		// error of the value, which is the error of the decoding, but with ReportErrorsWithLegacySemantics, which goes
		// on after it as v1 does
		return 0, .v2Error()
	}
	if  != nil {
		return 0, 
	}
	if .Option.V2&V2AllowInvalidUTF8 == 0 && !validV2Text([:]) {
		return 0, errV2Text
	}
	return , nil
}

// decodeByKind decodes the value at cursor into the nil interface value at p as a value of the type of its kind,
// by the decoder of the functions of unmarshaling, which the interface value is set to.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := anyValueTypes[.Buf[]]
	if  == nil {
		return 0, syntaxErrorAt(.Buf, , whereValue)
	}
	 := reflect.New()
	,  := .DecoderOfV2(runtime.TypePtr(.Type()))
	if  != nil {
		return 0, 
	}
	,  := .Decode(, , , .UnsafePointer())
	valueAt(.ptrType, ).Set(.Elem())
	return , 
}

// decodeHeld decodes the value at cursor into the value which the interface value at p holds, as encoding/json/v2
// decodes it: into a copy of the value, which the interface value is set to. A pointer is the data word of the
// interface value, which it is decoded into in place of the copy: the interface value is set as the copy would set it.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	if  := heldType(, .empty); runtime.TypeOfPtr().Kind() == reflect.Pointer {
		if  := *interfaceData();  != nil && .v2Funcs() == nil {
			// the value which the pointer points to, decoded through it by the decoder of its pointer type, as the
			// decoder of a pointer to the pointer decodes a pointer which is not nil: without the type of a pointer to
			// the pointer, which reflect makes by a lookup, as the program has none. The functions of unmarshaling
			// are given the pointer to the pointer too, as encoding/json/v2 gives it, by the decoder of that pointer.
			,  := .DecoderOfV2()
			if  != nil {
				return 0, 
			}
			return .Decode(, , , )
		}
		,  := .DecoderOfV2(ptrTypeOf(runtime.TypeOfPtr()))
		if  != nil {
			return 0, 
		}
		return .Decode(, , , unsafe.Pointer(interfaceData()))
	}
	 := valueAt(.ptrType, )
	 := .Elem()
	if !.fromAny && (.Type() == interfaceMapType || .Type() == anySliceType) {
		return .decodeMerging(, , , )
	}
	 := reflect.New(.Type())
	.Elem().Set()
	,  := .DecoderOfV2(runtime.TypePtr(.Type()))
	if  != nil {
		return 0, 
	}
	,  := .Decode(, , , .UnsafePointer())
	.Set(.Elem())
	return , 
}

// holdsPointer reports whether the interface value at p, which holds a value, holds a pointer which is not nil: the
// only value which MergeWithLegacySemantics decodes into, through the pointer, while any other is dropped before the
// value is decoded.
func ( *v2InterfaceDecoder) ( unsafe.Pointer) bool {
	return runtime.TypeOfPtr(heldType(, .empty)).Kind() == reflect.Pointer && *interfaceData() != nil
}

// heldType returns the type of the value which the interface value at p holds, which is not nil: the first word of
// an interface{}, if empty, or else the second word of the itab, the first word of an interface value of an interface
// type with methods.
func heldType( unsafe.Pointer,  bool) unsafe.Pointer {
	 := *(*unsafe.Pointer)()
	if ! {
		 = (*[2]unsafe.Pointer)()[1]
	}
	return 
}

// interfaceData returns the address of the data word of the interface value at p, of an interface type with methods
// or not: its second word, after its type or its itab.
func interfaceData( unsafe.Pointer) *unsafe.Pointer {
	return &(*[2]unsafe.Pointer)()[1]
}

// decodeMerging decodes the object or the array at cursor into the interface{} at p, which holds nothing, a
// map[string]interface{}, which the object is merged into, or a []interface{}, whose array is reused: the value of a
// name the map has is decoded into the value of the name, as the value of a name which the object has twice, which
// V2AllowDuplicateNames lets it have, is decoded into the value of the first one.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	 := *(*any)()
	switch [] {
	case '{':
		,  := .(map[string]any)
		if  != nil && ! {
			return .skipTypeError(, , reflect.TypeOf())
		}
		if  == nil {
			 = map[string]any{}
			*(*any)() = 
		}
		return .decodeObjectInto(, , , )
	case '[':
		,  := .([]any)
		if  != nil && ! {
			return .skipTypeError(, , reflect.TypeOf())
		}
		,  := .decodeArrayInto(, , , &)
		*(*any)() = 
		return , 
	}
	if  != nil {
		return .skipTypeError(, , reflect.TypeOf())
	}
	return .Decode(, , , )
}

// decodeElem decodes the value at cursor of an object or an array which decodeMerging decodes, into the interface{}
// at p, which holds the value of its name in the map, or nothing: an object or an array into nothing is decoded by
// decodeMerging too, so that the input is read once, whatever names it has twice.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 = skipWhiteSpace(.Buf, )
	var  int64
	var  error
	if  := .Buf[]; ( == '{' ||  == '[') && *(*any)() == nil {
		,  = .decodeMerging(, , , )
	} else {
		,  = .Decode(, , , )
	}
	if  != nil {
		// with ReportErrorsWithLegacySemantics, the decoding goes on after the value, as v2GoOnDecoder goes on: a
		// value of another kind than the one it is merged into, as an object into a []any, fails
		return .goOnAfter(, , )
	}
	return , nil
}

// decodeObjectInto decodes the object at cursor into m, merging the value of a name into the value of the name
// which m has.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  map[string]any) (int64, error) {
	 := .Buf
	++
	if  > maxDecodeNestingDepth {
		return 0, errors.ErrExceededMaxDepth([], )
	}
	 = skipWhiteSpace(, +1)
	if [] == '}' {
		return  + 1, nil
	}
	var  nameSet
	for {
		if [] != '"' {
			return 0, syntaxErrorAt(, , whereKey)
		}
		, , ,  := .fast.stringDecoder.decodeString(, )
		if  != nil {
			return 0, 
		}
		if .Option.V2&V2AllowInvalidUTF8 == 0 && strings.IndexByte(, 0xef) >= 0 && !validV2Text([:]) {
			return 0, errV2Text
		}
		if .Option.V2&V2AllowDuplicateNames == 0 && !.addCopy(.V2Call(), nil, unsafeBytes()) {
			return 0, errV2Text
		}
		 = skipWhiteSpace(, )
		if [] != ':' {
			return 0, syntaxErrorAt(, , whereAfterKey)
		}
		// the value of the name which m has, which is decoded into, but with MergeWithLegacySemantics, which replaces
		// it
		var  any
		if .Option.V2&V2MergeWithLegacySemantics == 0 {
			 = []
		}
		,  = .decodeElem(, +1, , unsafe.Pointer(&))
		[] = 
		if  != nil {
			return 0, 
		}
		 = skipWhiteSpace(, )
		switch [] {
		case '}':
			.end(.v2)
			return  + 1, nil
		case ',':
			 = skipWhiteSpace(, +1)
		default:
			return 0, syntaxErrorAt(, , whereAfterPair)
		}
	}
}

// decodeArrayInto decodes the array at cursor into *s from its first element, which is set to nil before.
func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64,  *[]any) (int64, error) {
	 := .Buf
	++
	if  > maxDecodeNestingDepth {
		return 0, errors.ErrExceededMaxDepth([], )
	}
	* = (*)[:0]
	if * == nil {
		* = []any{}
	}
	 = skipWhiteSpace(, +1)
	if [] == ']' {
		return  + 1, nil
	}
	for {
		* = append(*, nil)
		,  := .decodeElem(, , , unsafe.Pointer(&(*)[len(*)-1]))
		if  != nil {
			return 0, 
		}
		 = skipWhiteSpace(, )
		switch [] {
		case ']':
			return  + 1, nil
		case ',':
			++
		default:
			return 0, syntaxErrorAt(, , whereAfterElement)
		}
	}
}

func ( *v2InterfaceDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: v2 decoder does not support decode path")
}

// maxListedNames is the number of the names of an object which a nameSet compares a name with: past it, they are
// kept in a map, so that an object of many names is not quadratic in its names.
const maxListedNames = 32

// nameSet is the names of an object, among which add finds a name that the object has twice: the n entries of the
// names of the call from the entry first ( see callNames ), and the copies from copies on, whose bits are in mask,
// and past maxListedNames, the keys of set too. A name whose bit is not in mask is not compared with the names, as
// most names are not. The zero nameSet has no name.
type nameSet struct {
	first, n, copies int
	mask             nameMask
	set              map[string]struct{}
}

// nameMask is the bits of the hashes of the names of an object ( see nameHash ), one of 256 for each name: the top
// eight bits of the hash, of which the top two choose the word and the next six the bit in the word.
type nameMask [4]uint64

// bit returns the word of the mask which has the bit of the hash h, and the bit.
func ( *nameMask) ( uint64) (*uint64, uint64) {
	return &[>>62], uint64(1) << ( >> 56 & 63)
}

// maxWordsName is the length of the longest name of the input whose hash is made of its words where the input has
// it, two words of eight bytes ( see inputNameWords ), if the input has room for them from the start of the name.
const maxWordsName = 16

// add adds the name buf[start:end] of the input, which is not written while the object is decoded, and reports
// whether the set didn't have it.
func ( *nameSet) ( *V2Call,  []byte, ,  int64) bool {
	return .insert(, , [:], )
}

// addListed adds the name buf[start:end] of the input as add adds it, if it can without a call, and reports whether
// it did: a name of up to maxWordsName bytes, where buf has room for two words from start, of an object of fewer than
// maxListedNames names, whose bit is not in the mask, in an entry of the array of the call which has room. It makes
// no call, so that it has no frame and doesn't save its arguments, as insert does for the calls on its other paths:
// the loops which add most names call it before add.
func ( *nameSet) ( *V2Call,  []byte, ,  int64) bool {
	 :=  - 
	if  > maxWordsName || +maxWordsName > int64(cap()) || .set != nil || .n >= maxListedNames {
		return false
	}
	,  := inputNameWords(, , )
	 := mixNameWords(, , )
	 := &.names
	 := .entries
	,  := .mask.bit()
	if *& != 0 || len() >= cap() {
		return false
	}
	* |= 
	if .n == 0 {
		.first, .copies = len(), len(.copies)
	}
	// within the capacity, which the compiler sees, so that the slice and the index need no call of a panic, and the
	// length of the entries of the call written alone: their array is the same, without the write barrier of its
	// pointer
	 = [:len()+1]
	[len()-1] = nameEntry{hash: , at: , n: }
	(*sliceHeader)(unsafe.Pointer(&.entries)).len = len()
	.n++
	return true
}

// inputNameWords returns the words of the name buf[at:at+n] of the input of up to maxWordsName bytes, where buf has
// room for two words from at, as nameHash makes them of its bytes: the first word without the bytes after the name,
// and the last one for more than eight bytes.
func inputNameWords( []byte, ,  int64) (uint64, uint64) {
	,  := load64(, ), uint64(0)
	if  < 8 {
		// the n low bytes of the word, which load64 reads little-endian: the mask of the shift, which is less than
		// 64, tells the compiler so
		 &= 1<<(uint()*8&63) - 1
	} else if  > 8 {
		// the last eight bytes, which overlap the first word if the name is shorter than 16
		 = load64(, +-8)
	}
	return , 
}

// addCopy adds a copy of the name, and reports whether the set didn't have it: buf is the input of the names which
// add added to the set, if any.
func ( *nameSet) ( *V2Call, ,  []byte) bool {
	return .insert(, , , -1)
}

// insert adds the name, at the offset at of buf, the input, or copied if at is negative, and reports whether the set
// didn't have it. The hash of a name of the input of up to 16 bytes is made here of its words, as nameHash makes it,
// where buf has room for two words from at. The name is compared with the names of its bit by their hashes, and with
// the ones of its hash by their bytes. The entries of the call are written after the ones of the objects which its
// object is in, which the keys of set are: they are not written while the object is open, as the objects in it end
// before its next name, and an array of copies which the call leaves for a larger one is not written again.
func ( *nameSet) ( *V2Call, ,  []byte,  int64) bool {
	 := &.names
	if .n == 0 {
		.first, .copies = len(.entries), len(.copies)
	}
	var  uint64
	if  := int64(len());  >= 0 &&  <= maxWordsName && +maxWordsName <= int64(cap()) {
		,  := inputNameWords(, , )
		 = mixNameWords(, , )
	} else {
		 = nameHash()
	}
	if .set != nil {
		if ,  := .set[unsafeString()];  {
			return false
		}
	} else if ,  := .mask.bit(); *& == 0 {
		* |= 
	} else {
		for  := range .entries[.first:] {
			if  := &.entries[.first+]; .hash ==  && .n == int64(len()) && string(.name(, )) == string() {
				return false
			}
		}
	}
	if  < 0 {
		 = -1 - int64(len(.copies))
		.copies = append(.copies, ...)
	}
	.entries = append(.entries, nameEntry{hash: , at: , n: int64(len())})
	.n++
	switch {
	case .set != nil:
		.set[unsafeString(.name(&.entries[len(.entries)-1], ))] = struct{}{}
	case .n > maxListedNames:
		.set = make(map[string]struct{}, 2*.n)
		for  := range .entries[.first:] {
			.set[unsafeString(.name(&.entries[.first+], ))] = struct{}{}
		}
	}
	return true
}

// end drops the names of the set from the names of the call, and its map, at the end of its object.
func ( *nameSet) ( *V2Call) {
	if .n != 0 {
		.names.truncate(.first, .copies)
		.set = nil
	}
}

// unsafeString is the string of the bytes of b, which are not written while it is used.
func unsafeString( []byte) string { return unsafe.String(unsafe.SliceData(), len()) }

// unsafeBytes is the bytes of the string s, which are not written.
func unsafeBytes( string) []byte { return unsafe.Slice(unsafe.StringData(), len()) }

// nameHash returns the hash of name, whose top eight bits are its bit in a nameMask: of its first word, of
// its first eight bytes, or of all of them for a name of less than eight bytes, mixed with the words between it and
// the last one, and of its last word, of its last eight bytes, for a name of more than eight bytes ( see
// mixNameWords ). The words of a name of up to maxWordsName bytes are all of its bytes.
func nameHash( []byte) uint64 {
	 := len()
	var ,  uint64
	if  >= 8 {
		 = binary.LittleEndian.Uint64()
		if  > 8 {
			 = binary.LittleEndian.Uint64([-8:])
			for  := 8;  < -8;  += 8 {
				 = ( ^ binary.LittleEndian.Uint64([:])) * 0x9E3779B97F4A7C15
			}
		}
	} else {
		// the bytes as one word, of the words of four bytes at both ends of the name, or of two, without the bytes
		// which the second word has of the first one
		switch {
		case  >= 4:
			 = uint64(binary.LittleEndian.Uint32()) | uint64(binary.LittleEndian.Uint32([-4:]))>>(8*(8-))<<32
		case  >= 2:
			 = uint64(binary.LittleEndian.Uint16()) | uint64(binary.LittleEndian.Uint16([-2:]))>>(8*(4-))<<16
		case  == 1:
			 = uint64([0])
		}
	}
	return mixNameWords(, , int64())
}

// mixNameWords returns the hash of a name of n bytes of the words a and b ( see nameHash ).
func mixNameWords(,  uint64,  int64) uint64 {
	 := ( ^ bits.RotateLeft64(, 29) ^ uint64()<<58) * 0x9E3779B97F4A7C15
	return  ^ >>31
}

// callNames are the names of no field, and the other names which are kept, of the objects of a call which are being
// decoded, as encoding/json/jsontext keeps the names of the objects which are open: the entries of the names of an
// object, after the ones of the objects which it is in ( see nameSet ). A name is kept by its place in the input, or
// by a copy in copies, for a name which the input doesn't hold as it is, or which a stream may move: the copies keep
// nothing of the input. An error ends the objects around the object of the error too, but in the value of a method of
// a stream, whose error the method may ignore: the names of the objects which an error ended are dropped at the end
// of the value of a stream which they are in ( see Stream.DecodeV2After ), or when the stream or the context is
// released. A call which no error ended leaves none.
type callNames struct {
	entries []nameEntry
	copies  []byte
}

// nameEntry is a name of an object: its hash, and its n bytes, at the offset at of the input, or at the offset -1-at
// of the copies.
type nameEntry struct {
	hash uint64
	at   int64
	n    int64
}

// name returns the name of e, whose input is buf.
func ( *callNames) ( *nameEntry,  []byte) []byte {
	if .at < 0 {
		 := -1 - .at
		return .copies[ : +.n]
	}
	return [.at : .at+.n]
}

// mark returns the numbers of the entries and of the copies of the names of the call, which truncate goes back to.
func ( *callNames) () (int, int) { return len(.entries), len(.copies) }

// truncate drops the entries from entries on, and the copies from copies on. Back to no name, it drops the arrays
// which a value of many names or long names made large, over the sizes over which an encoder of jsontext drops the
// arrays of its names ( see putEncoder ), so that a context in the pool doesn't pin them: then no object has a name
// in them.
func ( *callNames) (,  int) {
	const  = 64 << 10
	if  == 0 && (cap(.copies) >  || cap(.entries) > /int(unsafe.Sizeof(nameEntry{}))) {
		* = callNames{}
		return
	}
	.entries = .entries[:]
	.copies = .copies[:]
}