Skip to content

Commit

Permalink
docs: update SaramaCompatHasher documentation
Browse files Browse the repository at this point in the history
Updating the SaramaCompatHasher documentation with a function returning a fnv-1a hasher as fnv.New32a() does not return a func([]byte) uint32 out of the box.
  • Loading branch information
rrreeezzz committed May 27, 2024
1 parent 1c152ac commit ac2b9ce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/kgo/partitioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,16 @@ func SaramaHasher(hashFn func([]byte) uint32) PartitionerHasher {
//
// In short, to *exactly* match the Sarama defaults, use the following:
//
// kgo.StickyKeyPartitioner(kgo.SaramaCompatHasher(fnv.New32a()))
// kgo.StickyKeyPartitioner(kgo.SaramaCompatHasher(fnv32a))
//
// Where fnv32a is a function returning a new 32 bit fnv-1a hasher.
//
// func fnv32a(b []byte) uint32 {
// h := fnv.New32a()
// h.Reset()
// h.Write(b)
// return h.Sum32()
// }
func SaramaCompatHasher(hashFn func([]byte) uint32) PartitionerHasher {
return func(key []byte, n int) int {
p := int32(hashFn(key)) % int32(n)
Expand Down

0 comments on commit ac2b9ce

Please sign in to comment.