github.com/blend/go-sdk@v1.20220411.3/bitflag/bitflag.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package bitflag 9 10 // Combine combines all the values into one flag. 11 func Combine(values ...Bitflag) Bitflag { 12 var outputFlag uint64 13 for _, value := range values { 14 outputFlag = outputFlag | uint64(value) 15 } 16 return Bitflag(outputFlag) 17 } 18 19 // Bitflag is a large unsighted integer flag set. 20 type Bitflag uint64 21 22 // All returns if all of a given set of flags are set. 23 func (bf Bitflag) All(values Bitflag) bool { 24 return uint64(bf)&uint64(values) == uint64(values) 25 } 26 27 // Any returns if any the reference bits are set for a given value 28 func (bf Bitflag) Any(values Bitflag) bool { 29 return uint64(bf)&uint64(values) > 0 30 } 31 32 // Set sets a flag value to 1. 33 func (bf Bitflag) Set(values Bitflag) Bitflag { 34 return Bitflag(uint64(bf) | uint64(values)) 35 } 36 37 // Unset makes a given flag zero'd in the set. 38 func (bf Bitflag) Unset(values Bitflag) Bitflag { 39 return Bitflag(uint64(bf) ^ ((-(0) ^ uint64(values)) & uint64(bf))) 40 }