File: key_helpers.go

package info (click to toggle)
golang-github-weaveworks-mesh 0%2Bgit20161024.3dd75b1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 412 kB
  • sloc: sh: 59; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package metcd

// PrefixRangeEnd allows Get, Delete, and Watch requests to operate on all keys
// with a matching prefix. Pass the prefix to this function, and use the result
// as the RangeEnd value.
func PrefixRangeEnd(prefix []byte) []byte {
	// https://github.com/coreos/etcd/blob/17e32b6/clientv3/op.go#L187
	end := make([]byte, len(prefix))
	copy(end, prefix)
	for i := len(end) - 1; i >= 0; i-- {
		if end[i] < 0xff {
			end[i] = end[i] + 1
			end = end[:i+1]
			return end
		}
	}
	// next prefix does not exist (e.g., 0xffff);
	// default to WithFromKey policy
	return []byte{0}
}