-
Notifications
You must be signed in to change notification settings - Fork 568
/
prefix.go
29 lines (24 loc) · 1.1 KB
/
prefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package accum
import "fmt"
const (
modulePrefix = "accum"
accumulatorPrefix = "acc"
positionPrefix = "pos"
KeySeparator = "||" // needs to be different from other modules.
accumPrefixKey = modulePrefix + KeySeparator + accumulatorPrefix + KeySeparator
positionPrefixKey = modulePrefix + KeySeparator + positionPrefix + KeySeparator
)
// formatAccumPrefix returns the key prefix used
// specifically for accumulator values in the KVStore.
// Returns "accum||acc||{accumName}" as bytes.
func formatAccumPrefixKey(accumName string) []byte {
return []byte(fmt.Sprintf(accumPrefixKey+"%s", accumName))
}
// FormatPositionPrefixKey returns the key prefix used
// specifically for position values in the KVStore.
// Returns "accum||pos||{accumName}||{name}" as bytes.
// We use a different key separator, namely `||`, to separate the accumulator name and the position name.
// This is because we require that accumName does not contain this as a substring.
func FormatPositionPrefixKey(accumName, name string) []byte {
return []byte(fmt.Sprintf(positionPrefixKey+"%s"+KeySeparator+"%s", accumName, name))
}