github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/dispatch/keys/dispatchcheckkey.go (about) 1 package keys 2 3 import ( 4 "encoding/binary" 5 ) 6 7 // DispatchCacheKey is a struct which holds the key representing a dispatch operation being 8 // dispatched or cached. 9 type DispatchCacheKey struct { 10 stableSum uint64 11 processSpecificSum uint64 12 } 13 14 // StableSumAsBytes returns the stable portion of the dispatch cache key as bytes. Note that since 15 // this is only returning the result of one of the two sums, the returned bytes may not be fully 16 // unique for the input data. 17 func (dck DispatchCacheKey) StableSumAsBytes() []byte { 18 return binary.AppendUvarint(make([]byte, 0, 8), dck.stableSum) 19 } 20 21 // AsUInt64s returns the cache key in the form of two uint64's. This method returns uint64s created 22 // from two distinct hashing algorithms, which should make the risk of key overlap incredibly 23 // unlikely. 24 func (dck DispatchCacheKey) AsUInt64s() (uint64, uint64) { 25 return dck.processSpecificSum, dck.stableSum 26 } 27 28 var emptyDispatchCacheKey = DispatchCacheKey{0, 0}