Beispiel #1
0
func KeyToBytesAndPrefix(bucketId bucket.Id,
	separator SeparatorByte,
	key types.Key) []byte {

	var bucketKeyBytes []byte
	bucketKeyBytes = key.Serialize()
	return PrefixKeyBytes(bucketId, separator, bucketKeyBytes)
}
Beispiel #2
0
func isWithingRange(str string,
	start []byte, startIncluded bool,
	endOptional []byte, endIncluded bool) bool {

	givenKey := types.Key{[]byte(str)}
	givenBytes := givenKey.Serialize()

	startCmp := bytes.Compare(givenBytes, start)
	if startCmp < 0 || (startCmp == 0 && !startIncluded) {
		return false
	}
	// Check for end?
	if endOptional != nil {
		endCmp := bytes.Compare(givenBytes, endOptional)
		if endCmp > 0 || (endCmp == 0 && !endIncluded) {
			return false
		}
	}
	return true
}
Beispiel #3
0
func createScanRange(bucketId bucket.Id,
	start types.Key, startExclusive bool,
	endOptional types.Key, endExclusive bool) (r *util.Range, err error) {

	r = new(util.Range)

	// Start
	if start == nil {
		err = errors.New("Missing the start key (only end is optional)")
		return
	}
	r.Start = start.Serialize()
	if startExclusive {
		r.Start = incrementByOne(r.Start)
	}
	r.Start = PrefixKeyBytes(bucketId, SeparatorDefault, r.Start)

	// Limit / end
	if endOptional != nil {
		r.Limit = endOptional.Serialize()
		if !endExclusive {
			r.Limit = incrementByOne(r.Limit)
		}
		r.Limit = PrefixKeyBytes(bucketId, SeparatorDefault, r.Limit)
	} else {
		// No end. We take the SeparatorUpper special value ... will scan to the end of the
		// bucket.
		r.Limit = PrefixKeyBytes(bucketId, SeparatorUpper, []byte{})
	}

	compareResult := bytes.Compare(r.Start, r.Limit)
	if compareResult > 0 {
		err = errors.New("The start value is larger (lexicographically) than the end value.")
		return nil, err
	}

	return r, nil
}