seaweedfs/weed/storage/needle/file_id.go

36 lines
946 B
Go
Raw Normal View History

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