github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_int.go (about) 1 package jzon 2 3 import ( 4 "strconv" 5 ) 6 7 const ( 8 invalidDigit = -1 9 ) 10 11 var ( 12 intDigits [charNum]int8 13 ) 14 15 func init() { 16 for i := 0; i < charNum; i++ { 17 intDigits[i] = invalidDigit 18 } 19 for i := '0'; i <= '9'; i++ { 20 intDigits[i] = int8(i - '0') 21 } 22 } 23 24 // ReadInt reads an int value 25 func (it *Iterator) ReadInt() (int, error) { 26 if strconv.IntSize == 32 { 27 i, err := it.ReadInt32() 28 return int(i), err 29 } 30 i, err := it.ReadInt64() 31 return int(i), err 32 } 33 34 // ReadUint reads an uint value 35 func (it *Iterator) ReadUint() (uint, error) { 36 if strconv.IntSize == 32 { 37 u, err := it.ReadUint32() 38 return uint(u), err 39 } 40 u, err := it.ReadUint64() 41 return uint(u), err 42 }