package decoder

import (
	stderrors 
	
	
	
	
	
	

	
	
	
)

// A value of a stream is decoded from the buffer by the decoders of a byte slice when the buffer holds it whole. An
// object or an array which the buffer doesn't hold whole is decoded element by element instead, without a read for
// it: each element is decoded the same way, from the buffer if it holds the element whole, and else element by element
// in turn, so that the reader is read only when the next token isn't whole in the buffer. So the decoding never reads
// past the token being read, which fails a value at the read of its first invalid byte, and the buffer holds a read
// and the longest token, whatever the size of a value: the bytes of the elements decoded are dropped when the buffer
// is filled again. The strings decoded then are copied out of the buffer, which they would keep alive, unless
// NoCopyStringOption is set.
//
// The objects and the arrays of structs, maps, slices, arrays, pointers to them and interface{} values are decoded
// so. A value of any other type, as one which has an UnmarshalJSON method, which takes the bytes of the whole value,
// or a value of another kind than its type, whose type error the decoder of its type reports, is read whole, checked
// element by element as it is read ( see wholeEnd ).

// errLongValue is what a scan of a value returns for an object or an array which doesn't end within the bytes it may
// read ( see scanValue ).
var errLongValue = stderrors.New("json: value too long to be read whole")

// scanFailed returns the error of Decode for the error err of the scan of the value at the cursor, which Decode decodes
// into p, of the pointer type typ, by dec: a value too long to be read whole is decoded element by element, as Decode
// does a value whole, or read whole and decoded if dec doesn't decode it so.
//
//go:noinline
func ( *Stream) ( error,  Decoder, ,  unsafe.Pointer) error {
	if  != errLongValue {
		return .fail()
	}
	 := .ctx
	.Option = .Option
	 := .offset + .cursor
	if .elements == nil {
		// the entries of the first steps of the lookups ( see indexFirstStep ), which a slice grown from nothing
		// would take a few allocations for
		.elements = &bracketIndex{closes: make([]bracketClose, 0, indexFirstStep/4)}
	}
	if (.Option.Flags & NoCopyStringOption) != 0 {
		// the strings of the value refer to the buffer, which is not reused in place then ( see grow )
		.referred = true
	}
	*.elements = bracketIndex{closes: .elements.closes[:0], end: }
	,  := .decodeElements(, , 0)
	if ! {
		var  int64
		if ,  = .wholeEnd(0);  == nil {
			 = .decodeWhole(, , 0, )
		}
	}
	if  != nil {
		.DiscardTypeError()
		return .fail()
	}
	if countsScanned {
		.scanned += .offset + .cursor - .readStart
	}
	.more.reset()
	if .tokenState != tokenTopValue {
		.tokenValueEnd()
	}
	if  := .typeError;  != nil {
		.typeError = nil
		if .plain != nil {
			return .plain
		}
		// the steps were added from the value of the error up to the root ( see addTypeErrorStep )
		slices.Reverse(.path)
		return .toError(.path, runtime.TypeOfPtr(), )
	}
	return nil
}

// restAfter returns the error of Decode for err, the error of a member or an element of the object, if object is set,
// or the array which has the cursor after it, nested in depth objects and arrays: a syntax error or the end of the
// input as it is, and any other error once the rest of the object or the array is read, as a value read whole is read
// before its error is returned, whose syntax error or end is the error then.
func ( *Stream) ( error,  bool,  int64) error {
	if .grammarFailure() {
		return 
	}
	for {
		var  bool
		var  error
		if  {
			if _, _, _, ,  = .nextMember(false);  {
				 = .memberValue()
			}
		} else {
			,  = .nextElement(false)
		}
		if  != nil {
			return 
		}
		if ! {
			return 
		}
		if  = .skipNested();  != nil {
			return 
		}
	}
}

// grammarFailure reports whether err is a syntax error or the end of the input, which fail a value read whole before
// it is decoded: any other error is the one of an element which is decoded, as an unknown field.
func ( *Stream) ( error) bool {
	,  := .(*errors.SyntaxError)
	return  ||  == io.ErrUnexpectedEOF ||  == .readErr
}

// skipAfter returns the error of the decoding of the value at the cursor, nested in depth objects and arrays, which is
// whole in the buffer, and moves the cursor after it: a syntax error of the value first, as for a value read whole.
func ( *Stream) ( error,  int64) error {
	,  := skipValue(.buf[:.length+1], .cursor, )
	if  != nil {
		return .elementError(, )
	}
	.cursor = 
	return .totalOffsetError()
}

// decodeElements decodes the object or the array at the cursor, nested in depth objects and arrays, by dec into p
// element by element. It reports false, having read nothing, if dec doesn't decode it so.
func ( *Stream) ( Decoder,  unsafe.Pointer,  int64) (bool, error) {
	 := .buf[.cursor]
	switch d := .(type) {
	case *structDecoder:
		if  == '{' {
			return true, .decodeStructElements(, , )
		}
	case *mapDecoder:
		if  == '{' && !.keyUnsupported {
			return true, .decodeMapElements(, , )
		}
	case *sliceDecoder:
		if  == '[' {
			return true, .decodeSliceElements(, , )
		}
	case *arrayDecoder:
		if  == '[' {
			return true, .decodeArrayElements(, , )
		}
	case *ptrDecoder:
		 := *(*unsafe.Pointer)()
		 := 
		if  == nil {
			 = newValue(.typ)
			*(*unsafe.Pointer)() = 
		}
		,  := .(.dec, , )
		if  != nil || ! {
			// the pointer of a value read whole is set as ptrDecoder sets it, and the one of a value which fails is
			// left as it was, as the grammar of a value read whole fails it before it is decoded
			*(*unsafe.Pointer)() = 
		}
		return , 
	case *anonymousFieldDecoder:
		if *(*unsafe.Pointer)() == nil {
			*(*unsafe.Pointer)() = newValue(.structType)
		}
		return .(.dec, unsafe.Add(*(*unsafe.Pointer)(), .offset), )
	case *interfaceDecoder:
		return .decodeInterfaceElements(, , )
	case *bytesDecoder:
		if  == '[' {
			return .(.sliceDecoder, , )
		}
	}
	return false, nil
}

// decodeNested decodes the value at the cursor, nested in depth objects and arrays, by dec into p: whole if the
// buffer holds it, and else element by element.
func ( *Stream) ( Decoder,  unsafe.Pointer,  int64) error {
	if  := .buf[.cursor];  != '{' &&  != '[' && .decodeScalar(, , ) {
		return nil
	}
	, ,  := .elementEnd()
	if  != nil {
		return 
	}
	if ! {
		if ,  := .decodeElements(, , );  {
			return 
		}
		if ,  = .wholeEnd();  != nil {
			return 
		}
	}
	return .decodeWhole(, , , )
}

// decodeScalar decodes the value at the cursor, which is not an object or an array, nested in depth objects and
// arrays, by dec into p, if dec decodes a string, a number or a boolean, or a nil interface{} of v2 which calls nothing
// of the caller, without the steps of decodeWhole: a string is read whole first, and a number or a literal is decoded
// from what has been read. It reports false if the value doesn't end before the end of what has been read, or has an
// error: decodeWhole then reads it whole and decodes it again, and reports the error.
func ( *Stream) ( Decoder,  unsafe.Pointer,  int64) bool {
	switch d := .(type) {
	case *stringDecoder, *intDecoder, *uintDecoder, *floatDecoder, *boolDecoder, *numberDecoder, v2StringDecoder:
	case *v2InterfaceDecoder:
		// the value of a nil interface{} without functions of unmarshaling, which the decoder of v1 decodes ( see
		// v2InterfaceDecoder.Decode ): a value which an interface value holds may be decoded by a method, and a
		// function may be called, which read the place of the value in the stream ( see V2Call.Value )
		if !.empty || .fromAny || *(*any)() != nil {
			return false
		}
	default:
		return false
	}
	// the value is decoded only when it is whole, so that the decoder writes nothing of a part of it
	switch  := .buf[.cursor]; {
	case  == '"':
		, , ,  := .scanStringInfo()
		if  != nil || ! {
			return false
		}
		switch .(type) {
		case *stringDecoder, v2StringDecoder:
			if .firstEscape < 0 && !.nonASCII {
				// the bytes of a string without an escape, of ASCII, are its value, as decodeStringField and
				// decodeStringV2 make it: they are not scanned again
				 := .ctx
				.Buf = .buf[:.length+1]
				.origin = .Buf
				*(*string)() = .makeString(.buf[.cursor+1 : -1])
				.Buf, .origin = nil, nil
				.cursor = 
				return true
			}
		}
	case  == '-' || -'0' <= 9:
		// a number which a byte after it ends
		if ,  := jsonnum.Scan(.buf[.cursor:.length]);  != jsonnum.Valid || .cursor+int64() >= .length {
			return false
		}
	default:
		if  := literalOf();  == "" || .length-.cursor < int64(len()) {
			return false
		}
	}
	 := .ctx
	 := .typeError
	.Buf = .buf[:.length+1]
	.origin = .Buf
	,  := .Decode(, .cursor, , )
	.Buf, .origin = nil, nil
	if  != nil {
		.typeError = 
		return false
	}
	if  == nil && .typeError != nil {
		.keepTypeError()
	}
	.cursor = 
	return true
}

// wholeEnd returns the position after the object or the array at the cursor, nested in depth objects and arrays,
// which is read whole: its grammar is checked as it is read, keeping its bytes ( see skipNested ), so that a value
// which is not valid fails at its error, without the input after it being read, as a value decoded element by element
// does.
func ( *Stream) ( int64) (int64, error) {
	 := .offset + .cursor
	,  := .keeps, .keepFrom
	if !.keeps || .keepFrom >  {
		.keeps, .keepFrom = true, 
	}
	 := .skipNested()
	.keeps, .keepFrom = , 
	if  != nil {
		return 0, 
	}
	 := .cursor
	.cursor =  - .offset
	return , nil
}

// elementEnd returns the position after the value at the cursor, nested in depth objects and arrays. An object or an
// array is found by the index of the brackets in what has been read, and else whole is false; any other value is read
// whole.
func ( *Stream) ( int64) (int64, bool, error) {
	if  := .buf[.cursor];  != '{' &&  != '[' {
		,  := .scanValue()
		return , true, 
	}
	var  int
	// the index is extended by steps twice as large as the one before, so that it goes past the end of the element
	// by its size at most, and as many steps as the doublings of its size are taken
	for  := int64(indexFirstStep); ;  *= 2 {
		var  int64
		var  bool
		.indexFrom()
		if , ,  = .elements.closeOf(.offset+.cursor, , );  {
			return  + 1 - .offset, true, nil
		}
		if !.indexAhead() {
			return 0, false, nil
		}
	}
}

// bracketIndex is where the objects and the arrays of the value which a stream decodes element by element end, in
// what has been read: it is extended by every read, so that each byte is scanned once, and an element is found whole
// in the buffer by the index, without a scan of its own at every level it is nested in. Only the ones nested in at
// most bound objects and arrays have an entry: the elements looked up are the ones of the objects and the arrays
// decoded element by element, which are few levels, and the brackets of the blocks of bytes deeper in an element
// are not looked at one by one.
type bracketIndex struct {
	// closes are the brackets which close the objects and the arrays, in their order. An object or an array ends at
	// the first one after it which is as deep: the ones before are deeper, in it.
	closes []bracketClose
	// depth is the number of the objects and the arrays open after what has been read.
	depth int64
	// bound is the depth of the deepest brackets indexed: the depth of the closes ( see bracketClose ).
	bound int64
	// end is the total offset up to which what has been read is indexed.
	end int64
	// next is the first entry which closeOf looks at: the values are looked up in the order of the input.
	next int
	// inString and escaped are the state of the scan after what has been read ( see compoundScanner.scan ).
	inString, escaped uint64
}

// bracketClose is a bracket which closes an object or an array: its total offset, and the number of the objects and
// the arrays which the one it closes is nested in, plus one for itself.
type bracketClose struct {
	at, depth int64
}

// indexAt makes the index have what has been read from the cursor, where an element nested in depth objects and
// arrays is ( see indexFrom ).
func ( *Stream) ( int64) {
	.indexFrom()
	 := .elements
	.extend(.buf, .end-.offset, .length, .offset)
	.end = .offset + .length
}

// indexFrom makes the index go on from the cursor, where an element nested in depth objects and arrays is: it is
// extended by the bytes read since it was looked at last, as long as the lookups of the elements went on from it, and
// else made from the cursor, which a skip of elements left it behind, or which is deeper than the index has its
// entries. A deeper index is four times as deep as what it is made for, so that a value nested deep, which is decoded
// element by element at every level, has its bytes indexed again a few times only.
func ( *Stream) ( int64) {
	 := .elements
	if  := .offset + .cursor; .end <  || .bound < +1 {
		 := len(.closes)
		for  > .next && .closes[-1].at >  {
			--
		}
		.closes = .closes[:]
		if .bound < +1 {
			.bound = 4 * max(+1, .bound)
		}
		.depth, .inString, .escaped, .end = , 0, 0, 
	}
}

// indexFirstStep is what a lookup of the end of an element indexes first ( see elementEnd ), so that the bytes after
// the element, which a skip of elements may pass without the index, are not indexed for it: four blocks of the scan.
const indexFirstStep = 4 * scanBlockSize

// indexAhead extends the index by step bytes of what has been read at most, and reports false if it has all.
func ( *Stream) ( int64) bool {
	 := .elements
	 := min(.end-.offset+, .length)
	if .end-.offset >=  {
		return false
	}
	.extend(.buf, .end-.offset, , .offset)
	.end = .offset + 
	return true
}

// extend indexes buf[from:to], whose first byte is at the total offset offset.
func ( *bracketIndex) ( []byte, , ,  int64) {
	if .next >= 1024 && .next*2 >= len(.closes) {
		// the entries which closeOf looked past are dropped
		.closes = .closes[:copy(.closes, .closes[.next:])]
		.next = 0
	}
	const  = 0x5555555555555555
	 := (*sliceHeader)(unsafe.Pointer(&)).data
	, , , ,  := .closes, .depth, .bound, .inString, .escaped
	for  := ;  < ;  += scanBlockSize {
		// the brackets out of the strings in the block, as compoundScanner.scan finds them
		var  scanMasks
		scanBlock(unsafe.Add(, ), &)
		 :=  - 
		if  < scanBlockSize {
			 := uint64(1)<<uint() - 1
			.quote &= 
			.backslash &= 
			.open &= 
			.closing &= 
		}
		 := .backslash &^ 
		 := <<1 | 
		 :=  &^  &^ 
		,  := bits.Add64(, , 0)
		 := ( ^ ( << 1)) & 
		if  < scanBlockSize {
			 = ( >> uint()) & 1
		} else {
			 = 
		}
		 := .quote &^ 
		 ^=  << 1
		 ^=  << 2
		 ^=  << 4
		 ^=  << 8
		 ^=  << 16
		 ^=  << 32
		 ^= 
		 = uint64(int64() >> 63)
		 := ^( | )
		,  := .open&, .closing&
		if  == 0 || -int64(bits.OnesCount64()) >=  {
			// no bracket of the block closes an object or an array as shallow as the bound
			 += int64(bits.OnesCount64()) - int64(bits.OnesCount64())
			continue
		}
		for  :=  | ;  != 0;  &=  - 1 {
			 := bits.TrailingZeros64()
			if &(1<<uint()) != 0 {
				++
				continue
			}
			if  <=  {
				 = append(, bracketClose{at:  +  + int64(), depth: })
			}
			--
		}
	}
	.closes, .depth, .inString, .escaped = , , , 
}

// lastElementClose returns the total offset of the bracket which closes the last element which is an object or an
// array in what has been read of the elements from the total offset at, which are nested in depth objects and arrays.
func ( *bracketIndex) (,  int64) (int64, bool) {
	// the entries before are passed for good: the lookups are in the order of the input
	for .next < len(.closes) && .closes[.next].at <  {
		.next++
	}
	var  int64
	 := false
	for  := .next;  < len(.closes); ++ {
		 := .closes[]
		if .depth <=  {
			// the end of the array
			break
		}
		if .depth == +1 {
			,  = .at, true
		}
	}
	return , 
}

// closeOf returns the total offset of the bracket which closes the object or the array whose bracket is at the total
// offset at, nested in depth objects and arrays, if it has been read. The entries are looked at from the one rel
// after the first one which may close the value, which a lookup returns, so that the lookups of a value which has not
// been read whole go on after each other.
func ( *bracketIndex) (,  int64,  int) (int64, bool, int) {
	for .next < len(.closes) && .closes[.next].at <  {
		.next++
	}
	for  := .next + ;  < len(.closes); ++ {
		if .closes[].depth == +1 {
			return .closes[].at, true, 0
		}
	}
	return 0, false, len(.closes) - .next
}

// decodeWhole decodes the value at the cursor, which ends at end, nested in depth objects and arrays, by dec into p,
// as Decode does a value.
func ( *Stream) ( Decoder,  unsafe.Pointer, ,  int64) error {
	 := .ctx
	 := .typeError
	,  := .callDecoder(, , , )
	if  != nil {
		if ,  := .(*errors.SyntaxError);  {
			return .elementError(, )
		}
		.typeError = 
		return .skipAfter(, )
	}
	if  == nil && .typeError != nil {
		.keepTypeError()
	}
	.cursor = 
	return nil
}

// elementError returns the error of the decoding of the value at the cursor, nested in depth objects and arrays, as
// decodeError does: a syntax error is the first one of the value by the grammar.
func ( *Stream) ( error,  int64) error {
	if ,  := .(*errors.SyntaxError);  {
		if  := .valueSyntaxErrorAt();  != nil {
			return 
		}
	}
	return .totalOffsetError()
}

// keepTypeError makes the type error recorded in the value at the cursor one of the whole input: its path from the
// value is made while the buffer holds the value, and the objects and the arrays the value is in add theirs to it
// ( see addTypeErrorStep ).
func ( *Stream) () {
	 := .ctx.typeError
	if .plain == nil {
		.path = typeErrorPath(.buf[:.length+1], .cursor, )
		slices.Reverse(.path)
	}
	.start += .offset
	.end += .offset
}

// addTypeErrorStep adds the step to a member or an element, named name, to the path of the type error recorded in
// it: the decoding of the member or the element had none before, which it is called for. The path is kept from the
// value up to the root, so that a step is added without a copy of the path.
func ( *Stream) ( string) {
	 := .ctx.typeError
	.path = append(.path, )
}

// syntaxError returns the syntax error of the byte at the cursor, which the grammar doesn't have where it is.
func ( *Stream) ( syntaxWhere) error {
	return .grammarError(syntaxErrorAt(.buf[:.length+1], .cursor, ))
}

// nextElement moves the cursor to the next element of the array whose elements are read: first is set before the
// first one. It reports false after the end of the array.
func ( *Stream) ( bool) (bool, error) {
	if !.skipWhiteSpace() {
		return false, .unexpectedEndError()
	}
	switch  := .buf[.cursor]; {
	case  == ']':
		.cursor++
		return false, nil
	case :
		return true, nil
	case  != ',':
		return false, .syntaxError(whereAfterElement)
	}
	.cursor++
	if !.skipWhiteSpace() {
		return false, .unexpectedEndError()
	}
	return true, nil
}

// nextMember moves the cursor after the key of the next member of the object whose members are read: first is set
// before the first one. It returns the key as the buffer has it, which the next read of the stream may drop, what it
// has, and the position it starts at. It reports false after the end of the object.
func ( *Stream) ( bool) ([]byte, stringInfo, int64, bool, error) {
	if !.skipWhiteSpace() {
		return nil, stringInfo{}, 0, false, .unexpectedEndError()
	}
	switch  := .buf[.cursor]; {
	case  == '}':
		.cursor++
		return nil, stringInfo{}, 0, false, nil
	case :
	case  != ',':
		return nil, stringInfo{}, 0, false, .syntaxError(whereAfterPair)
	default:
		.cursor++
		if !.skipWhiteSpace() {
			return nil, stringInfo{}, 0, false, .unexpectedEndError()
		}
	}
	if .buf[.cursor] != '"' {
		return nil, stringInfo{}, 0, false, .syntaxError(whereKey)
	}
	, , ,  := .scanStringInfo()
	if  != nil {
		return nil, stringInfo{}, 0, false, 
	}
	 := .cursor
	if  {
		.cursor = 
		return .buf[+1 : -1], , , true, nil
	}
	// the error of the key
	, , ,  := skipStringDecoder.scanString(.buf[:.length+1], )
	if  < 0 {
		, , ,  = skipStringDecoder.scanStringRest(.buf[:.length+1], , --1, )
	}
	if  != nil {
		return nil, stringInfo{}, 0, false, .elementError(, 0)
	}
	.cursor = 
	return , , , true, nil
}

// openElements moves the cursor after the bracket which opens the object or the array whose elements are read, nested
// in depth objects and arrays, and returns the depth of its elements. A bracket nested too deep is the syntax error
// which the grammar of a value read whole reports ( see skipGrammar ), wherever the reads of the input end.
func ( *Stream) ( int64) (int64, error) {
	if  >= maxDecodeNestingDepth {
		return 0, .grammarError(depthSyntaxError(.buf[:.length+1], .cursor))
	}
	.cursor++
	return  + 1, nil
}

// memberValue moves the cursor from after the key of a member to its value.
func ( *Stream) () error {
	if !.skipWhiteSpace() {
		return .unexpectedEndError()
	}
	if .buf[.cursor] != ':' {
		return .syntaxError(whereAfterKey)
	}
	.cursor++
	if !.skipWhiteSpace() {
		return .unexpectedEndError()
	}
	return nil
}

// skipNested skips the value at the cursor, nested in depth objects and arrays, which is checked by the grammar, as
// skipValue does, reading from the reader as the value goes on past what has been read: skipFast stops at the end of
// what has been read, and resumes after the read where it stopped, so that each byte is checked once, before the next
// read.
func ( *Stream) ( int64) error {
	if  := .buf[.cursor];  != '{' &&  != '[' {
		return .skipScalar()
	}
	if  >= maxDecodeNestingDepth {
		return .grammarError(depthSyntaxError(.buf[:.length+1], .cursor))
	}
	 := skipMaxLevel()
	, , ,  := .cursor, int64(0), uint64(0), resumeValue
	for {
		var  skipEvent
		, , , ,  = skipFast(.buf[:.length+1], , , , , )
		.cursor = 
		switch  {
		case skipDone:
			return nil
		case skipAString, skipANumber:
			// a string or a number which skipFast leaves to its caller
			if  := .skipScalar();  != nil {
				return 
			}
		case skipDeep:
			if  := .( + );  != nil {
				return 
			}
			 = resumeAfterValue
		default:
			var  error
			if , ,  = .skipResume(, , );  != nil ||  == 0 {
				return 
			}
		}
		 = .cursor
	}
}

// skipScalar skips the value at the cursor, which is not an object or an array, as skipValue does: one which is whole
// and valid in what has been read is skipped by one scan, and any other is read whole first.
func ( *Stream) () error {
	switch  := .buf[.cursor]; {
	case  == '"':
		, , ,  := .scanStringInfo()
		if  != nil {
			return 
		}
		if  {
			.cursor = 
			return nil
		}
	case  == '-' || -'0' <= 9:
		// a number which a byte after it ends
		if ,  := jsonnum.Scan(.buf[.cursor:.length]);  == jsonnum.Valid && .cursor+int64() < .length {
			.cursor += int64()
			return nil
		}
		if ,  := .scanLiteral();  != nil {
			return 
		}
	default:
		if  := literalOf();  != "" && .length-.cursor >= int64(len()) && string(.buf[.cursor:.cursor+int64(len())]) ==  {
			.cursor += int64(len())
			return nil
		}
		if ,  := .scanValue();  != nil {
			return 
		}
	}
	,  := skipValue(.buf[:.length+1], .cursor, 0)
	if  != nil {
		return .elementError(, 0)
	}
	.cursor = 
	return nil
}

// skipError returns the syntax error of the byte at the cursor, where skipFast stopped in the state resume, with level
// objects and arrays open whose kinds are the bits of objects.
func ( *Stream) ( int64,  uint64,  skipResume) error {
	return .grammarError(skipFastError(.buf[:.length+1], .cursor, , , ))
}

// skipResume does what skipFast stopped at the cursor for, in the state resume, with level objects and arrays open
// whose kinds are the bits of objects: a byte which the grammar doesn't have there, whose syntax error it returns, or
// the end of what has been read, for which it reads, and returns the level and the state which skipFast resumes in at
// the cursor then. The level is 0 after the end of the value.
func ( *Stream) ( int64,  uint64,  skipResume) (int64, skipResume, error) {
	if .cursor < .length {
		 := literalOf(.buf[.cursor])
		if  := .length - .cursor;  != resumeValue ||  >= int64(len()) || string(.buf[.cursor:.length]) != [:] {
			return 0, 0, .skipError(, , )
		}
		// true, false or null which what has been read cuts
		if !.read() {
			return 0, 0, .unexpectedEndError()
		}
		return , , nil
	}
	switch  {
	case resumeAfterValue:
		if .cursor == 0 || .buf[.cursor-1]-'0' > 9 {
			break
		}
		// an integer, which the next bytes may go on: it is read whole, up to a byte after it, or the end of the input,
		// which the read below reports
		for .cursor > 0 && isNumberByte(.buf[.cursor-1]) {
			.cursor--
		}
		if  := .skipScalar();  != nil || .cursor < .length {
			return , , 
		}
	case resumeValue, resumeKey:
		// a value or a key, after the white space after a bracket, a comma or a colon: the end of the object or the
		// array may follow its bracket only, and the key is skipped here, as skipFast doesn't resume at it
		 := max(.cursor-1, 0)
		for  > 0 && isWhiteSpace[.buf[]] {
			--
		}
		 := byte(0)
		switch .buf[] {
		case '[':
			 = ']'
		case '{':
			 = '}'
		}
		if !.skipWhiteSpace() {
			return 0, 0, .unexpectedEndError()
		}
		switch  := .buf[.cursor]; {
		case  != 0 &&  == :
			.cursor++
			return  - 1, resumeAfterValue, nil
		case  == resumeKey &&  == '"':
			return , resumeAfterKey, .skipScalar()
		case  == resumeKey:
			return 0, 0, .skipError(, , )
		}
		return , , nil
	}
	if !.read() {
		return 0, 0, .unexpectedEndError()
	}
	return , , nil
}

// isNumberByte reports whether c is a byte of a number.
func isNumberByte( byte) bool {
	return -'0' <= 9 ||  == '.' ||  == 'e' ||  == 'E' ||  == '+' ||  == '-'
}

// decodeStructElements decodes the object at the cursor into the struct at p, as structDecoder.Decode does.
func ( *Stream) ( *structDecoder,  unsafe.Pointer,  int64) error {
	,  := .openElements()
	if  != nil {
		return 
	}
	 := .ctx.Option.Flags
	 := &DisallowUnknownFieldsOption != 0
	// seen are the fields decoded under FirstWinOption, by their indexes, and seenNum their number: once every one
	// is decoded, the rest of the object is skipped, as decodeObjectFirstWin does.
	var  []uint64
	if &FirstWinOption != 0 {
		 = make([]uint64, (.fieldUniqueNameNum+63)/64)
	}
	 := 0
	var  [64]byte
	for  := true; ;  = false {
		, , , ,  := .nextMember()
		if ! {
			return 
		}
		var  *structFieldSet
		var  []byte
		if  == 0 ||  < .fieldUniqueNameNum {
			var  []byte
			,  = .keys.lookup(, )
			if  == nil &&  {
				 := unknownFieldError()
				if  := .memberValue();  != nil {
					return 
				}
				if  := .skipNested();  != nil {
					return 
				}
				return .restAfter(, true, )
			}
			if  != nil {
				// the name of the step of a type error of the value, which a read may overwrite in the buffer
				 = append([:0], ...)
			}
		}
		 :=  != nil && .unsettable()
		if  != nil &&  != nil && ! {
			,  := &[.fieldIdx/64], uint64(1)<<uint(.fieldIdx%64)
			if *& != 0 {
				 = nil
			} else {
				* |= 
				++
			}
		}
		if  := .memberValue();  != nil {
			return 
		}
		 := .ctx.typeError
		switch {
		case  == nil:
			 = .skipNested()
		case :
			 = .skipUnsettable(, .err, )
		default:
			 = .decodeNested(.dec, unsafe.Add(, .offset), )
		}
		if  != nil {
			return .restAfter(, true, )
		}
		if .ctx.typeError !=  {
			.addTypeErrorStep(string())
		}
	}
}

// skipUnsettable skips the value at the cursor, nested in depth objects and arrays, of a field of the struct of d which
// can't be set ( see structFieldSet.unsettable ), and records err, its error, as structDecoder.Decode does.
func ( *Stream) ( *structDecoder,  error,  int64) error {
	,  := .offset+.cursor, kindOf(.buf[.cursor])
	if  := .skipNested();  != nil {
		return 
	}
	.ctx.unsettableValueError(, .offset+.cursor, , .typ, )
	return nil
}

// decodeMapElements decodes the object at the cursor into the map at p, as mapDecoder.Decode does.
func ( *Stream) ( *mapDecoder,  unsafe.Pointer,  int64) error {
	,  := .openElements()
	if  != nil {
		return 
	}
	 := *(*unsafe.Pointer)()
	if  == nil {
		 = reflect.MakeMap(.mapType).UnsafePointer()
	}
	 := .temps.Get().(*mapTemps)
	 := .mapValue()
	var  [64]byte
	for  := true; ;  = false {
		, , , ,  := .nextMember()
		if  != nil {
			return 
		}
		if ! {
			*(*unsafe.Pointer)() = 
			.temps.Put()
			return nil
		}
		// the name of the entry, which a type error in it reports
		 := append([:0], ...)
		 := .ctx.typeError
		// the key is decoded by the decoder of the keys, as a value which ends after it
		 := .cursor
		.cursor = 
		,  := .callDecoder(.keyDecoder, .k, , )
		 :=  == errMapKeyType
		if ,  := .(*errors.SyntaxError);  {
			return .elementError(, )
		}
		if  != nil && ! {
			// the error of a key is returned once the rest of the object is read
			.ctx.typeError = 
			.cursor = 
			if  := .memberValue();  != nil {
				return 
			}
			if  := .skipNested();  != nil {
				return 
			}
			return .restAfter(.totalOffsetError(), true, )
		}
		if  == nil && .ctx.typeError != nil {
			.keepTypeError()
		}
		.cursor = 
		if  := .memberValue();  != nil {
			return 
		}
		if  {
			// the value of an entry which is dropped is skipped, as encoding/json does
			 = .skipNested()
		} else if  = .decodeNested(.valueDecoder, .v, );  == nil {
			.SetMapIndex(.kv, .vv)
		}
		if  != nil {
			return .restAfter(, true, )
		}
		.kv.SetZero()
		.vv.SetZero()
		if .ctx.typeError !=  {
			.addTypeErrorStep(string(decodeLiteral(, )))
		}
	}
}

// decodeSliceElements decodes the array at the cursor into the slice at p, as sliceDecoder.Decode does.
func ( *Stream) ( *sliceDecoder,  unsafe.Pointer,  int64) error {
	,  := .openElements()
	if  != nil {
		return 
	}
	 := (*sliceHeader)()
	// the elements are decoded into the slice up to limit, and into a buffer after it, as Decode does
	 := sliceTarget{d: , dst: , limit: max(.cap, inPlaceSliceLength)}
	for  := 0; ; {
		,  := .nextElement( == 0)
		if  != nil || ! {
			.finish(, , )
			return 
		}
		if ,  := .decodeRun(&, , );  != nil ||  >  {
			if  = ;  != nil {
				return .sliceElementsError(&, , , )
			}
			continue
		}
		 := .ctx.typeError
		if  := .decodeNested(.valueDecoder, .elem(), );  != nil {
			return .sliceElementsError(&, , , )
		}
		.decoded()
		if .ctx.typeError !=  {
			.addTypeErrorStep(strconv.Itoa())
		}
		++
	}
}

// sliceElementsError returns the error of Decode for err, the error of the element idx of the array which t stores,
// whose elements are nested in depth objects and arrays. The slice has the element when err is not one of the grammar,
// as the slice which sliceDecoder.Decode decodes it into, which has a decoded value whose error is returned after it.
func ( *Stream) ( *sliceTarget,  int,  error,  int64) error {
	// the element idx is decoded into, whole or in part, whether the slice has it or not
	 :=  + 1
	if !.grammarFailure() {
		.decoded()
		++
	}
	.finish(, , )
	return .restAfter(, false, )
}

// sliceTarget is where the elements of an array decoded element by element are stored: into the slice up to limit,
// and into a buffer of the pool after it, as sliceDecoder.Decode does.
type sliceTarget struct {
	d     *sliceDecoder
	dst   *sliceHeader
	elems *sliceBuf
	limit int
}

// elem returns where the element at idx is decoded into.
func ( *sliceTarget) ( int) unsafe.Pointer {
	switch {
	case  < .limit:
		.d.grow(.dst, , +1)
		return unsafe.Add(.dst.data, uintptr()*.d.size)
	case .elems == nil:
		.elems = .d.takeBuf(.dst, )
	}
	return .d.bufElem(.elems, )
}

// decoded counts the element at idx, which is decoded, in the length of the slice.
func ( *sliceTarget) ( int) {
	if  < .limit {
		.dst.len =  + 1
	}
}

// finish makes the slice have the n elements decoded, after the end of the array or the error err: used elements are
// decoded into, whole or in part.
func ( *sliceTarget) (,  int,  error) {
	switch {
	case .elems != nil:
		.d.storeBuf(.dst, .elems, , )
	case  == nil &&  == 0 && .dst.data == nil:
		.dst.data = unsafe.Pointer(&zeroBase)
	default:
		.dst.len = 
	}
}

// decodeRun decodes the elements of the array from the one at the cursor, the element idx, which the buffer holds
// whole, by one setting of the decoders' buffer: the ones up to the last object or array element whose end has been
// read. It returns the number of the elements decoded with idx, and leaves the cursor after the last one. The
// elements of the array are nested in depth objects and arrays.
func ( *Stream) ( *sliceTarget,  int,  int64) (int, error) {
	.indexAt()
	,  := .elements.lastElementClose(.offset+.cursor, )
	if ! {
		return , nil
	}
	 := .ctx
	 :=  - .offset + 1
	 := .buf[]
	.buf[] = nul
	 := .buf[:+1]
	.Buf, .origin = , 
	 := .cursor
	var  error
	for {
		 := 
		 := .typeError
		,  := .d.valueDecoder.Decode(, , , .elem())
		if  != nil {
			.typeError = 
			// bytes of the grammar of a number which are more than one value, as 01 is 0 and 1, are decoded one by one
			// ( see scanLiteral ): the decoding stops before them, after the comma before them
			if !moreThanNumber(, ) {
				.cursor,  = , 
			}
			break
		}
		.decoded()
		if  == nil && .typeError != nil {
			.cursor = 
			.keepTypeError()
			.addTypeErrorStep(strconv.Itoa())
		}
		++
		.cursor = 
		// the next element is in the run if it starts before its end
		if  := skipWhiteSpace(, ); [] == ',' {
			if  = skipWhiteSpace(, +1);  <  {
				 = 
				continue
			}
		}
		break
	}
	.buf[] = 
	.Buf, .origin = nil, nil
	if ,  := .(*errors.SyntaxError);  {
		return , .elementError(, )
	}
	if  != nil {
		return , .skipAfter(, )
	}
	return , nil
}

// moreThanNumber reports whether the bytes of the grammar of a number at start in buf, which a nul byte ends, are more
// than a number, as 01 is 0 and 1.
func moreThanNumber( []byte,  int64) bool {
	 := 
	for isNumberByte([]) {
		++
	}
	,  := jsonnum.Scan([:])
	return  >  && +int64() < 
}

// decodeArrayElements decodes the array at the cursor into the array at p, as arrayDecoder.Decode does.
func ( *Stream) ( *arrayDecoder,  unsafe.Pointer,  int64) error {
	,  := .openElements()
	if  != nil {
		return 
	}
	for  := 0; ; ++ {
		,  := .nextElement( == 0)
		if  != nil {
			return 
		}
		if ! {
			.zeroFrom(, )
			return nil
		}
		if  >= .alen {
			if  := .skipNested();  != nil {
				return 
			}
			continue
		}
		 := .ctx.typeError
		if  := .decodeNested(.valueDecoder, unsafe.Add(, uintptr()*.size), );  != nil {
			return .restAfter(, false, )
		}
		if .ctx.typeError !=  {
			.addTypeErrorStep(strconv.Itoa())
		}
	}
}

// decodeInterfaceElements decodes the object or the array at the cursor into the interface value at p, as
// interfaceDecoder.Decode does. It reports false for a value of an interface type with methods which is kept, whose
// value is a type error, and, as decodeElements does, for a pointer which the interface value holds whose value is
// read whole.
func ( *Stream) ( *interfaceDecoder,  unsafe.Pointer,  int64) (bool, error) {
	// the value is found by its type, or by its itab for an interface type with methods
	,  := (*emptyInterface)().typ, (*emptyInterface)().ptr
	if .hasMethods {
		,  = (*nonEmptyInterface)().itab, (*nonEmptyInterface)().ptr
	}
	if  != nil {
		 := .values.Load(uintptr())
		if  == nil {
			 := reflect.NewAt(.typ, ).Elem().Interface()
			var  error
			if ,  = .valueDecoderOf(.ctx, , );  != nil {
				if  := .skipNested();  != nil {
					return true, 
				}
				return true, 
			}
		}
		if .kind == ifaceValuePointee {
			// what the pointer points to is decoded into, as a value of the pointer type
			return .decodeElements(.dec, , )
		}
	}
	if .hasMethods {
		return false, nil
	}
	var  any
	var  error
	if .buf[.cursor] == '{' {
		,  = .decodeAnyObject(, )
	} else {
		,  = .decodeAnyArray(, )
	}
	if  != nil {
		return true, 
	}
	*(*any)() = 
	return true, nil
}

// decodeAnyObject decodes the object at the cursor into a new map[string]interface{}, as decodeNewStringAnyMap does:
// the entries are pushed to the stack of entries of the context, and put into a map of their number at the end.
func ( *Stream) ( *interfaceDecoder,  int64) (any, error) {
	,  := .openElements()
	if  != nil {
		return nil, 
	}
	 := .ctx
	 := len(.entryStack)
	for  := true; ;  = false {
		, , , ,  := .nextMember()
		if ! {
			if  != nil {
				.popEntries()
				return nil, 
			}
			 := .entryStack[:]
			 := make(map[string]any, len())
			for  := range  {
				[[].key] = [].value
			}
			.popEntries()
			return , nil
		}
		 := string(decodeLiteral(, ))
		if  := .memberValue();  != nil {
			.popEntries()
			return nil, 
		}
		 := .typeError
		if  := .decodeNested(, unsafe.Pointer(&.slot), );  != nil {
			.slot = nil
			.popEntries()
			return nil, .restAfter(, true, )
		}
		.entryStack = append(.entryStack, anyEntry{key: , value: .slot})
		.slot = nil
		if .typeError !=  {
			.addTypeErrorStep()
		}
	}
}

// decodeAnyArray decodes the array at the cursor into a new []interface{}, as decodeAnySlice does: the elements are
// pushed to the stack of the context, and copied into a slice of their number at the end.
func ( *Stream) ( *interfaceDecoder,  int64) (any, error) {
	,  := .openElements()
	if  != nil {
		return nil, 
	}
	 := .ctx
	 := len(.anyStack)
	for  := 0; ; ++ {
		,  := .nextElement( == 0)
		if  != nil {
			.popAny()
			return nil, 
		}
		if ! {
			if  == 0 {
				return emptyAnySlice, nil
			}
			 := make([]any, )
			copy(, .anyStack[:])
			.popAny()
			return , nil
		}
		 := .typeError
		if  := .decodeNested(, unsafe.Pointer(&.slot), );  != nil {
			.slot = nil
			.popAny()
			return nil, .restAfter(, false, )
		}
		.anyStack = append(.anyStack, .slot)
		.slot = nil
		if .typeError !=  {
			.addTypeErrorStep(strconv.Itoa())
		}
	}
}