示例#1
0
func (s *testPrefixSuite) TestCode(c *C) {
	table := []struct {
		prefix string
		h      int64
		ID     int64
	}{
		{"123abc##!@#((_)((**&&^^%$", 1234567890, 0},
		{"", 1, 0},
		{"", -1, 0},
		{"", -1, 1},
	}

	for _, t := range table {
		b := EncodeRecordKey(t.prefix, t.h, t.ID)
		handle, err := DecodeHandleFromRowKey(string(b))
		c.Assert(err, IsNil)
		c.Assert(handle, Equals, t.h)
	}

	b1 := EncodeRecordKey("aa", 1, 0)
	b2 := EncodeRecordKey("aa", 1, 1)
	c.Logf("%#v, %#v", b2, b1)
	raw, err := codec.StripEnd(b1)
	c.Assert(err, IsNil)
	f := hasPrefix(raw)
	has := f(b2)
	c.Assert(has, IsTrue)
}
示例#2
0
// RowKeyPrefixFilter returns a function which checks whether currentKey has decoded rowKeyPrefix as prefix.
func RowKeyPrefixFilter(rowKeyPrefix []byte) kv.FnKeyCmp {
	return func(currentKey kv.Key) bool {
		// Next until key without prefix of this record.
		raw, err := codec.StripEnd(rowKeyPrefix)
		if err != nil {
			return false
		}
		return !bytes.HasPrefix(currentKey, raw)
	}
}