maeqtt/mqtt/types/Utils.go

20 lines
324 B
Go
Raw Normal View History

2021-08-26 15:08:24 +02:00
package types
// Returns 1 if b is true and 0 if false
func BoolToUint(b bool) uint {
if b {
return 1
}
return 0
}
// Reinterprets a slice of bools as a uint
// This method doesn't check for overflow
func BoolsToUint(b ...bool) uint {
var res uint
for i, v := range b {
res += BoolToUint(v) << i
}
return res
}