package jsoniter

import (
	
	
)

var intDigits []int8

const uint32SafeToMultiply10 = uint32(0xffffffff)/10 - 1
const uint64SafeToMultiple10 = uint64(0xffffffffffffffff)/10 - 1
const maxFloat64 = 1<<53 - 1

func init() {
	intDigits = make([]int8, 256)
	for  := 0;  < len(intDigits); ++ {
		intDigits[] = invalidCharForNumber
	}
	for  := int8('0');  <= int8('9'); ++ {
		intDigits[] =  - int8('0')
	}
}

// ReadUint read uint
func ( *Iterator) () uint {
	if strconv.IntSize == 32 {
		return uint(.ReadUint32())
	}
	return uint(.ReadUint64())
}

// ReadInt read int
func ( *Iterator) () int {
	if strconv.IntSize == 32 {
		return int(.ReadInt32())
	}
	return int(.ReadInt64())
}

// ReadInt8 read int8
func ( *Iterator) () ( int8) {
	 := .nextToken()
	if  == '-' {
		 := .readUint32(.readByte())
		if  > math.MaxInt8+1 {
			.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(), 10))
			return
		}
		return -int8()
	}
	 := .readUint32()
	if  > math.MaxInt8 {
		.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(), 10))
		return
	}
	return int8()
}

// ReadUint8 read uint8
func ( *Iterator) () ( uint8) {
	 := .readUint32(.nextToken())
	if  > math.MaxUint8 {
		.ReportError("ReadUint8", "overflow: "+strconv.FormatInt(int64(), 10))
		return
	}
	return uint8()
}

// ReadInt16 read int16
func ( *Iterator) () ( int16) {
	 := .nextToken()
	if  == '-' {
		 := .readUint32(.readByte())
		if  > math.MaxInt16+1 {
			.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(), 10))
			return
		}
		return -int16()
	}
	 := .readUint32()
	if  > math.MaxInt16 {
		.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(), 10))
		return
	}
	return int16()
}

// ReadUint16 read uint16
func ( *Iterator) () ( uint16) {
	 := .readUint32(.nextToken())
	if  > math.MaxUint16 {
		.ReportError("ReadUint16", "overflow: "+strconv.FormatInt(int64(), 10))
		return
	}
	return uint16()
}

// ReadInt32 read int32
func ( *Iterator) () ( int32) {
	 := .nextToken()
	if  == '-' {
		 := .readUint32(.readByte())
		if  > math.MaxInt32+1 {
			.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(), 10))
			return
		}
		return -int32()
	}
	 := .readUint32()
	if  > math.MaxInt32 {
		.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(), 10))
		return
	}
	return int32()
}

// ReadUint32 read uint32
func ( *Iterator) () ( uint32) {
	return .readUint32(.nextToken())
}

func ( *Iterator) ( byte) ( uint32) {
	 := intDigits[]
	if  == 0 {
		.assertInteger()
		return 0 // single zero
	}
	if  == invalidCharForNumber {
		.ReportError("readUint32", "unexpected character: "+string([]byte{byte()}))
		return
	}
	 := uint32()
	if .tail-.head > 10 {
		 := .head
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return 
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *10 + uint32()
		}
		//iter.head = i + 1
		//value = value * 100 + uint32(ind2) * 10 + uint32(ind3)
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *100 + uint32()*10 + uint32()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *1000 + uint32()*100 + uint32()*10 + uint32()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *10000 + uint32()*1000 + uint32()*100 + uint32()*10 + uint32()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *100000 + uint32()*10000 + uint32()*1000 + uint32()*100 + uint32()*10 + uint32()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *1000000 + uint32()*100000 + uint32()*10000 + uint32()*1000 + uint32()*100 + uint32()*10 + uint32()
		}
		++
		 := intDigits[.buf[]]
		 = *10000000 + uint32()*1000000 + uint32()*100000 + uint32()*10000 + uint32()*1000 + uint32()*100 + uint32()*10 + uint32()
		.head = 
		if  == invalidCharForNumber {
			.assertInteger()
			return 
		}
	}
	for {
		for  := .head;  < .tail; ++ {
			 = intDigits[.buf[]]
			if  == invalidCharForNumber {
				.head = 
				.assertInteger()
				return 
			}
			if  > uint32SafeToMultiply10 {
				 := ( << 3) + ( << 1) + uint32()
				if  <  {
					.ReportError("readUint32", "overflow")
					return
				}
				 = 
				continue
			}
			 = ( << 3) + ( << 1) + uint32()
		}
		if !.loadMore() {
			.assertInteger()
			return 
		}
	}
}

// ReadInt64 read int64
func ( *Iterator) () ( int64) {
	 := .nextToken()
	if  == '-' {
		 := .readUint64(.readByte())
		if  > math.MaxInt64+1 {
			.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(), 10))
			return
		}
		return -int64()
	}
	 := .readUint64()
	if  > math.MaxInt64 {
		.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(), 10))
		return
	}
	return int64()
}

// ReadUint64 read uint64
func ( *Iterator) () uint64 {
	return .readUint64(.nextToken())
}

func ( *Iterator) ( byte) ( uint64) {
	 := intDigits[]
	if  == 0 {
		.assertInteger()
		return 0 // single zero
	}
	if  == invalidCharForNumber {
		.ReportError("readUint64", "unexpected character: "+string([]byte{byte()}))
		return
	}
	 := uint64()
	if .tail-.head > 10 {
		 := .head
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return 
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *10 + uint64()
		}
		//iter.head = i + 1
		//value = value * 100 + uint32(ind2) * 10 + uint32(ind3)
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *100 + uint64()*10 + uint64()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *1000 + uint64()*100 + uint64()*10 + uint64()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *10000 + uint64()*1000 + uint64()*100 + uint64()*10 + uint64()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *100000 + uint64()*10000 + uint64()*1000 + uint64()*100 + uint64()*10 + uint64()
		}
		++
		 := intDigits[.buf[]]
		if  == invalidCharForNumber {
			.head = 
			.assertInteger()
			return *1000000 + uint64()*100000 + uint64()*10000 + uint64()*1000 + uint64()*100 + uint64()*10 + uint64()
		}
		++
		 := intDigits[.buf[]]
		 = *10000000 + uint64()*1000000 + uint64()*100000 + uint64()*10000 + uint64()*1000 + uint64()*100 + uint64()*10 + uint64()
		.head = 
		if  == invalidCharForNumber {
			.assertInteger()
			return 
		}
	}
	for {
		for  := .head;  < .tail; ++ {
			 = intDigits[.buf[]]
			if  == invalidCharForNumber {
				.head = 
				.assertInteger()
				return 
			}
			if  > uint64SafeToMultiple10 {
				 := ( << 3) + ( << 1) + uint64()
				if  <  {
					.ReportError("readUint64", "overflow")
					return
				}
				 = 
				continue
			}
			 = ( << 3) + ( << 1) + uint64()
		}
		if !.loadMore() {
			.assertInteger()
			return 
		}
	}
}

func ( *Iterator) () {
	if .head < .tail && .buf[.head] == '.' {
		.ReportError("assertInteger", "can not decode float as int")
	}
}