package decoder

import (
	
	
	

	
)

type uintDecoder struct {
	typ        reflect.Type
	kind       reflect.Kind
	op         func(unsafe.Pointer, uint64)
	structName string
	fieldName  string
}

func newUintDecoder( reflect.Type, ,  string,  func(unsafe.Pointer, uint64)) *uintDecoder {
	return &uintDecoder{
		typ:        ,
		kind:       uintKindOf(),
		op:         ,
		structName: ,
		fieldName:  ,
	}
}

// uintKindOf returns the kind of the unsigned integers of the size of typ, whose range the decoder checks: a uint
// and a uintptr are a uint32 on a 32-bit platform.
func uintKindOf( reflect.Type) reflect.Kind {
	switch .Size() {
	case 1:
		return reflect.Uint8
	case 2:
		return reflect.Uint16
	case 4:
		return reflect.Uint32
	}
	return reflect.Uint64
}

func ( *uintDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	if [] == 'n' {
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if .Option.V2&(V2Semantics|V2MergeWithLegacySemantics) == V2Semantics {
			// the semantics of encoding/json/v2 decode null as the zero value, but with MergeWithLegacySemantics
			.op(, 0)
		}
		return  + 4, nil
	}
	if []-'0' > 9 {
		return .decodeSlow(, , , )
	}
	 := 
	, ,  := parseDigits(, )
	if isFloatContinuation([]) ||  > maxUint64Digits+1 {
		return .decodeSlow(, , , )
	}
	if  == maxUint64Digits+1 {
		var  bool
		if ,  = jsonnum.TwentyDigits(, ); ! {
			return .decodeSlow(, , , )
		}
	}
	switch .kind {
	case reflect.Uint8:
		if (1 << 8) <=  {
			return .decodeSlow(, , , )
		}
	case reflect.Uint16:
		if (1 << 16) <=  {
			return .decodeSlow(, , , )
		}
	case reflect.Uint32:
		if (1 << 32) <=  {
			return .decodeSlow(, , , )
		}
	}
	.op(, )
	return , nil
}

// decodeSlow decodes the value at cursor, which Decode doesn't: a value of another kind, a negative number or
// a number which is not an integer of the type, which are type errors, or a syntax error. It is a function of its
// own, so that Decode keeps the size it had.
//
//go:noinline
func ( *uintDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	switch  := []; {
	case  == 'n':
		if  := validateNull(, );  != nil {
			return 0, 
		}
		return  + 4, nil
	case  == '-':
		// a negative number, which the error reports
		,  := numberEnd(, )
		if  != nil {
			return 0, 
		}
		return .numberError(, , .typ)
	case -'0' > 9:
		// a value of another kind
		return .skipTypeError(, , .typ)
	}
	 := 
	, ,  := parseDigits(, )
	if isFloatContinuation([]) ||  > maxUint64Digits+1 {
		// a number which is not an integer, or too large for any integer
		,  := numberEnd(, )
		if  != nil {
			return 0, 
		}
		return .numberError(, , .typ)
	}
	if  == maxUint64Digits+1 {
		var  bool
		if ,  = jsonnum.TwentyDigits(, ); ! {
			return .numberError(, , .typ)
		}
	}
	switch .kind {
	case reflect.Uint8:
		if (1 << 8) <=  {
			return .numberError(, , .typ)
		}
	case reflect.Uint16:
		if (1 << 16) <=  {
			return .numberError(, , .typ)
		}
	case reflect.Uint32:
		if (1 << 32) <=  {
			return .numberError(, , .typ)
		}
	}
	.op(, )
	return , nil
}

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