SizeInt tells you how many bytes are needed to encode this signed number.
(number T)
| 4 | |
| 5 | // SizeInt tells you how many bytes are needed to encode this signed number. |
| 6 | func SizeInt[T int | int8 | int16 | int32 | int64](number T) int { |
| 7 | x := int64(number) |
| 8 | |
| 9 | switch { |
| 10 | case x >= math.MinInt8 && x <= math.MaxInt8: |
| 11 | return 1 |
| 12 | case x >= math.MinInt16 && x <= math.MaxInt16: |
| 13 | return 2 |
| 14 | case x >= math.MinInt32 && x <= math.MaxInt32: |
| 15 | return 4 |
| 16 | default: |
| 17 | return 8 |
| 18 | } |
| 19 | } |
no outgoing calls