package decoder

import (
	
	
	

	
)

type arrayDecoder struct {
	elemType reflect.Type
	// arrayPtrType is the type descriptor of the pointer to the array.
	arrayPtrType unsafe.Pointer
	size         uintptr
	valueDecoder Decoder
	alen         int
	structName   string
	fieldName    string
	// typ is the type of the array, which the type errors report.
	typ reflect.Type
}

func newArrayDecoder( Decoder,  reflect.Type, ,  string) *arrayDecoder {
	 := .Elem()
	return &arrayDecoder{
		typ:          ,
		valueDecoder: ,
		elemType:     ,
		arrayPtrType: ptrTypeOf(),
		size:         .Size(),
		alen:         .Len(),
		structName:   ,
		fieldName:    ,
	}
}

// zeroFrom sets the elements of the array at p from idx to the end to their zero value,
// as encoding/json does for the elements the JSON array has not.
func ( *arrayDecoder) ( unsafe.Pointer,  int) {
	if  < .alen {
		valueAt(.arrayPtrType, ).Slice(, .alen).Clear()
	}
}

func ( *arrayDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	for {
		switch [] {
		case ' ', '\n', '\t', '\r':
			++
			continue
		case 'n':
			if  := validateNull(, );  != nil {
				return 0, 
			}
			 += 4
			return , nil
		case '[':
			// only an array nests its values one level deeper: null or another value at the limit is not too deep
			++
			if  > maxDecodeNestingDepth {
				return 0, errors.ErrExceededMaxDepth([], )
			}
			 := 0
			++
			 = skipWhiteSpace(, )
			if [] == ']' {
				.zeroFrom(, )
				++
				return , nil
			}
			for {
				if  < .alen {
					,  := .valueDecoder.Decode(, , , unsafe.Add(, uintptr()*.size))
					if  != nil {
						return 0, 
					}
					 = 
				} else {
					,  := skipValue(, , )
					if  != nil {
						return 0, 
					}
					 = 
				}
				++
				 = skipWhiteSpace(, )
				switch [] {
				case ']':
					.zeroFrom(, )
					++
					return , nil
				case ',':
					++
					continue
				default:
					return 0, errors.ErrInvalidCharacter([], "array", )
				}
			}
		default:
			return .decodeOther(, , )
		}
	}
}

// decodeOther skips the value at cursor, which is not an array: a value of another kind is a type error, and
// anything else a syntax error. It is a function of its own, so that Decode keeps the size it had.
//
//go:noinline
func ( *arrayDecoder) ( *RuntimeContext, ,  int64) (int64, error) {
	if isOtherValue(.Buf[], arrayValue) {
		return .skipTypeError(, , .typ)
	}
	return 0, errors.ErrUnexpectedEndOfJSON("array", )
}

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