2013-04-16 15:10:21 +08:00
|
|
|
package storage
|
2011-12-20 17:00:01 +08:00
|
|
|
|
|
|
|
import (
|
2013-02-27 14:54:22 +08:00
|
|
|
"encoding/hex"
|
2018-07-08 17:28:04 +08:00
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
2011-12-20 17:00:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type FileId struct {
|
2013-04-16 15:10:21 +08:00
|
|
|
VolumeId VolumeId
|
2018-07-08 17:28:04 +08:00
|
|
|
Key NeedleId
|
|
|
|
Cookie Cookie
|
2011-12-20 17:00:01 +08:00
|
|
|
}
|
|
|
|
|
2014-03-24 12:57:10 +08:00
|
|
|
func NewFileIdFromNeedle(VolumeId VolumeId, n *Needle) *FileId {
|
2018-07-08 17:28:04 +08:00
|
|
|
return &FileId{VolumeId: VolumeId, Key: n.Id, Cookie: n.Cookie}
|
2011-12-20 17:00:01 +08:00
|
|
|
}
|
2018-07-08 17:28:04 +08:00
|
|
|
|
|
|
|
func NewFileId(VolumeId VolumeId, key uint64, cookie uint32) *FileId {
|
|
|
|
return &FileId{VolumeId: VolumeId, Key: Uint64ToNeedleId(key), Cookie: Uint32ToCookie(cookie)}
|
2011-12-20 17:00:01 +08:00
|
|
|
}
|
2018-07-08 17:28:04 +08:00
|
|
|
|
2011-12-20 17:00:01 +08:00
|
|
|
func (n *FileId) String() string {
|
2018-07-22 08:41:21 +08:00
|
|
|
return n.VolumeId.String() + "," + formatNeedleIdCookie(n.Key, n.Cookie)
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatNeedleIdCookie(key NeedleId, cookie Cookie) string {
|
2018-07-08 17:28:04 +08:00
|
|
|
bytes := make([]byte, NeedleIdSize+CookieSize)
|
2018-07-22 08:41:21 +08:00
|
|
|
NeedleIdToBytes(bytes[0:NeedleIdSize], key)
|
|
|
|
CookieToBytes(bytes[NeedleIdSize:NeedleIdSize+CookieSize], cookie)
|
2011-12-20 17:00:01 +08:00
|
|
|
nonzero_index := 0
|
|
|
|
for ; bytes[nonzero_index] == 0; nonzero_index++ {
|
|
|
|
}
|
2018-07-22 08:41:21 +08:00
|
|
|
return hex.EncodeToString(bytes[nonzero_index:])
|
2011-12-20 17:00:01 +08:00
|
|
|
}
|