func GenerateTableKey(tableID int64) []byte {
	buf := make([]byte, 0, len(tablePrefix)+8)
	buf = append(buf, tablePrefix...)
	buf = EncodeInt(buf, tableID)
	return buf
}
GenerateTableKey generates a table split key.
package codec
import (
	"bytes"
	"encoding/binary"
	"github.com/pingcap/errors"
)
var (
	tablePrefix  = []byte{'t'}
	metaPrefix   = []byte{'m'}
	recordPrefix = []byte("_r")
)
const (
	signMask uint64 = 0x8000000000000000
	encGroupSize = 8
	encMarker    = byte(0xFF)
	encPad       = byte(0x0)
)
type Key []byte
func (k Key) TableID() int64 {
	_, key, err := DecodeBytes(k)
	if err != nil {
		return 0
	}
	if !bytes.HasPrefix(key, tablePrefix) {
		return 0
	}
	key = key[len(tablePrefix):]
	_, tableID, _ := DecodeInt(key)
	return tableID
}
func (k Key) MetaOrTable() (bool, int64) {
	_, key, err := DecodeBytes(k)
	if err != nil {
		return false, 0
	}
	if bytes.HasPrefix(key, metaPrefix) {
		return true, 0
	}
	if bytes.HasPrefix(key, tablePrefix) {
		key = key[len(tablePrefix):]
		_, tableID, _ := DecodeInt(key)
		return false, tableID
	}
	return false, 0
}
var pads = make([]byte, encGroupSize)
func EncodeBytes(data []byte) Key {
	dLen := len(data)
	result := make([]byte, 0, (dLen/encGroupSize+1)*(encGroupSize+1))
	for idx := 0; idx <= dLen; idx += encGroupSize {
		remain := dLen - idx
		padCount := 0
		if remain >= encGroupSize {
			result = append(result, data[idx:idx+encGroupSize]...)
		} else {
			padCount = encGroupSize - remain
			result = append(result, data[idx:]...)
			result = append(result, pads[:padCount]...)
		}
		marker := encMarker - byte(padCount)
		result = append(result, marker)
	}
	return result
}
func EncodeInt(b []byte, v int64) []byte {
	var data [8]byte
	u := encodeIntToCmpUint(v)
	binary.BigEndian.PutUint64(data[:], u)
	return append(b, data[:]...)
}
func DecodeInt(b []byte) ([]byte, int64, error) {
	if len(b) < 8 {
		return nil, 0, errors.New("insufficient bytes to decode value")
	}
	u := binary.BigEndian.Uint64(b[:8])
	v := decodeCmpUintToInt(u)
	b = b[8:]
	return b, v, nil
}
func encodeIntToCmpUint(v int64) uint64 {
	return uint64(v) ^ signMask
}
func decodeCmpUintToInt(u uint64) int64 {
	return int64(u ^ signMask)
}
func DecodeBytes(b []byte) ([]byte, []byte, error) {
	data := make([]byte, 0, len(b))
	for {
		if len(b) < encGroupSize+1 {
			return nil, nil, errors.New("insufficient bytes to decode value")
		}
		groupBytes := b[:encGroupSize+1]
		group := groupBytes[:encGroupSize]
		marker := groupBytes[encGroupSize]
		padCount := encMarker - marker
		if padCount > encGroupSize {
			return nil, nil, errors.Errorf("invalid marker byte, group bytes %q", groupBytes)
		}
		realGroupSize := encGroupSize - padCount
		data = append(data, group[:realGroupSize]...)
		b = b[encGroupSize+1:]
		if padCount != 0 {
			var padByte = encPad
			for _, v := range group[realGroupSize:] {
				if v != padByte {
					return nil, nil, errors.Errorf("invalid padding byte, group bytes %q", groupBytes)
				}
			}
			break
		}
	}
	return b, data, nil
}