SplitKey takes a key baseKey and generates the key of the list split that starts at startUid.
(baseKey []byte, startUid uint64)
| 510 | |
| 511 | // SplitKey takes a key baseKey and generates the key of the list split that starts at startUid. |
| 512 | func SplitKey(baseKey []byte, startUid uint64) ([]byte, error) { |
| 513 | keyCopy := make([]byte, len(baseKey)+8) |
| 514 | copy(keyCopy, baseKey) |
| 515 | |
| 516 | if keyCopy[0] != DefaultPrefix { |
| 517 | return nil, errors.Errorf("only keys with default prefix can have a split key") |
| 518 | } |
| 519 | // Change the first byte (i.e the key prefix) to ByteSplit to signal this is an |
| 520 | // individual part of a single list key. |
| 521 | keyCopy[0] = ByteSplit |
| 522 | |
| 523 | // Append the start uid at the end of the key. |
| 524 | binary.BigEndian.PutUint64(keyCopy[len(baseKey):], startUid) |
| 525 | return keyCopy, nil |
| 526 | } |
| 527 | |
| 528 | // Parse would parse the key. ParsedKey does not reuse the key slice, so the key slice can change |
| 529 | // without affecting the contents of ParsedKey. |