Moved sizeof functions to a separate package

This commit is contained in:
Eduard Urbach 2024-07-29 12:33:28 +02:00
parent 6d77a8a120
commit 315ad23e31
Signed by: eduard
GPG key ID: 49226B848C78F6C8
13 changed files with 83 additions and 40 deletions

View file

@ -0,0 +1,20 @@
package sizeof
import "math"
// Unsigned tells you how many bytes are needed to encode this unsigned number.
func Unsigned(number uint64) int {
switch {
case number <= math.MaxUint8:
return 1
case number <= math.MaxUint16:
return 2
case number <= math.MaxUint32:
return 4
default:
return 8
}
}