func QueueStateKey(id uint64, group []byte) []byte {
	n := len(group)
	key := make([]byte, n+9, n+9)
	goetty.Uint64ToBytesTo(id, key)
	key[8] = queueStateField
	copy(key[9:], group)
	return key
}
QueueStateKey returns concurrency queue key
package storage
import (
	"time"
	"github.com/deepfabric/busybee/pkg/pb/metapb"
	"github.com/fagongzi/goetty"
	"github.com/fagongzi/util/hack"
)
const (
	mappingIDPrefix            byte = 0
	mappingPrefix              byte = 1
	profilePrefix              byte = 2
	tenantMetadataPrefix       byte = 3
	tenantRunnerPrefix         byte = 4
	tenantRunnerMetadataPrefix byte = 5
	tenantRunnerWorkerPrefix   byte = 6
	tenantRunnerLockKeyField   byte = 7
	tenantRunnerOffsetField    byte = 8
	workflowCurrentPrefix      byte = 9
	workflowHistoryPrefix      byte = 10
	workflowCrowdPrefix        byte = 11
	tempPrefix                 byte = 12
	outputPrefix               byte = 13
	bsiKeyPrefix               byte = 14
	queueMaxOffsetField     byte = 0
	queueRemovedOffsetField byte = 1
	queueItemField          byte = 2
	queueCommittedField     byte = 3
	queueKVField            byte = 4
	queueStateField         byte = 5
	queueMetaField          byte = 6
)
func TempKey(value []byte) []byte {
	n := 1 + 8 + len(value)
	key := make([]byte, n, n)
	key[0] = tempPrefix
	goetty.Int64ToBytesTo(time.Now().Unix(), key[1:])
	copy(key[9:], value)
	return key
}
func BSIKey(tid uint64, instanceID uint64, wid uint32, step []byte) []byte {
	n := 21 + len(step)
	key := make([]byte, n, n)
	key[0] = bsiKeyPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(instanceID, key[9:])
	goetty.Uint32ToBytesTo(wid, key[17:])
	copy(key[21:], step)
	return key
}
func OutputNotifyKey(tid uint64, ts int64, value []byte) []byte {
	n := 1 + 16 + len(value)
	key := make([]byte, n, n)
	key[0] = outputPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Int64ToBytesTo(ts, key[9:])
	copy(key[17:], value)
	return key
}
func outputNotifyKey(tid uint64, ts int64) []byte {
	n := 17
	key := make([]byte, n, n)
	key[0] = outputPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Int64ToBytesTo(ts, key[9:])
	return key
}
func PartitionKey(id uint64, partition uint32) []byte {
	key := make([]byte, 12, 12)
	goetty.Uint64ToBytesTo(id, key)
	goetty.Uint32ToBytesTo(partition, key[8:])
	return key
}
func QueueKVKey(id uint64, src []byte) []byte {
	n := 9 + len(src)
	key := make([]byte, n, n)
	goetty.Uint64ToBytesTo(id, key)
	key[8] = queueKVField
	copy(key[9:], src)
	return key
}
func TenantMetadataKey(id uint64) []byte {
	key := make([]byte, 9, 9)
	key[0] = tenantMetadataPrefix
	goetty.Uint64ToBytesTo(id, key[1:])
	return key
}
func WorkflowCurrentInstanceKey(id uint64) []byte {
	key := make([]byte, 9, 9)
	key[0] = workflowCurrentPrefix
	goetty.Uint64ToBytesTo(id, key[1:])
	return key
}
func WorkflowHistoryInstanceKey(wid, instanceID uint64) []byte {
	key := make([]byte, 17, 17)
	key[0] = workflowHistoryPrefix
	goetty.Uint64ToBytesTo(wid, key[1:])
	goetty.Uint64ToBytesTo(instanceID, key[9:])
	return key
}
func ShardBitmapKey(value []byte, index uint32) []byte {
	n := len(value)
	key := make([]byte, n+4, n+4)
	copy(key, value)
	goetty.Uint32ToBytesTo(index, key[n:])
	return key
}
func WorkflowCrowdShardKey(wid, instanceID uint64, version uint32) []byte {
	key := make([]byte, 21, 21)
	key[0] = workflowCrowdPrefix
	goetty.Uint64ToBytesTo(wid, key[1:])
	goetty.Uint64ToBytesTo(instanceID, key[9:])
	goetty.Uint32ToBytesTo(version, key[17:])
	return key
}
func TenantRunnerKey(tid uint64, runner uint64) []byte {
	key := make([]byte, 17, 17)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	return key
}
func TenantRunnerOffsetKey(tid uint64, runner uint64) []byte {
	key := make([]byte, 18, 18)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerOffsetField
	return key
}
func TenantRunnerLockKey(tid uint64, runner uint64, lockKey []byte) []byte {
	n := 18 + len(lockKey)
	key := make([]byte, n, n)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerLockKeyField
	copy(key[18:], lockKey)
	return key
}
func TenantRunnerMetadataKey(tid uint64, runner uint64) []byte {
	key := make([]byte, 18, 18)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerMetadataPrefix
	return key
}
func TenantRunnerWorkerMinKey(tid uint64, runner uint64) []byte {
	key := make([]byte, 18, 18)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerWorkerPrefix
	return key
}
func TenantRunnerWorkerMaxKey(tid uint64, runner uint64) []byte {
	key := make([]byte, 18, 18)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerWorkerPrefix + 1
	return key
}
func TenantRunnerWorkerInstanceMinKey(tid uint64, runner uint64, wid uint64) []byte {
	key := make([]byte, 26, 26)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerWorkerPrefix
	goetty.Uint64ToBytesTo(wid, key[18:])
	return key
}
func TenantRunnerWorkerInstanceMaxKey(tid uint64, runner uint64, wid uint64) []byte {
	key := make([]byte, 26, 26)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerWorkerPrefix
	goetty.Uint64ToBytesTo(wid+1, key[18:])
	return key
}
func TenantRunnerWorkerKey(tid uint64, runner uint64, wid uint64, worker uint32) []byte {
	key := make([]byte, 30, 30)
	key[0] = tenantRunnerPrefix
	goetty.Uint64ToBytesTo(tid, key[1:])
	goetty.Uint64ToBytesTo(runner, key[9:])
	key[17] = tenantRunnerWorkerPrefix
	goetty.Uint64ToBytesTo(wid, key[18:])
	goetty.Uint32ToBytesTo(worker, key[26:])
	return key
}
func MappingIDKey(tenantID uint64, userID uint32) []byte {
	key := make([]byte, 13, 13)
	key[0] = mappingIDPrefix
	goetty.Uint64ToBytesTo(tenantID, key[1:])
	goetty.Uint32ToBytesTo(userID, key[9:])
	return key
}
func MappingKey(tenantID uint64, from metapb.IDValue, to string) []byte {
	size := 9 + len(from.Value) + len(from.Type) + len(to)
	key := make([]byte, size, size)
	key[0] = mappingPrefix
	goetty.Uint64ToBytesTo(tenantID, key[1:])
	idx := 9
	copy(key[idx:], hack.StringToSlice(from.Type))
	idx += len(from.Type)
	copy(key[idx:], hack.StringToSlice(to))
	idx += len(to)
	copy(key[idx:], hack.StringToSlice(from.Value))
	return key
}
func ProfileKey(tenantID uint64, uid uint32) []byte {
	key := make([]byte, 13, 13)
	key[0] = profilePrefix
	goetty.Uint64ToBytesTo(tenantID, key[1:])
	goetty.Uint32ToBytesTo(uid, key[9:])
	return key
}
func maxOffsetKey(src []byte) []byte {
	n := len(src)
	key := make([]byte, n+1, n+1)
	copy(key, src)
	key[n] = queueMaxOffsetField
	return key
}
func removedOffsetKey(src []byte) []byte {
	n := len(src)
	key := make([]byte, n+1, n+1)
	copy(key, src)
	key[n] = queueRemovedOffsetField
	return key
}
func QueueItemKey(src []byte, offset uint64) []byte {
	n := len(src)
	key := make([]byte, n+9, n+9)
	copy(key, src)
	key[n] = queueItemField
	goetty.Uint64ToBytesTo(offset, key[n+1:])
	return key
}
func queueItemKey(src []byte, offset uint64, buf *goetty.ByteBuf) goetty.Slice {
	buf.MarkWrite()
	buf.Write(src)
	buf.WriteByte(queueItemField)
	buf.WriteUint64(offset)
	return buf.WrittenDataAfterMark()
}
func QueueMetaKey(id uint64, partition uint32) []byte {
	key := make([]byte, 13, 13)
	goetty.Uint64ToBytesTo(id, key)
	goetty.Uint32ToBytesTo(partition, key[8:])
	key[12] = queueMetaField
	return key
}