mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-22 03:57:23 +08:00
refactoring
This commit is contained in:
35
weed/storage/needle/file_id.go
Normal file
35
weed/storage/needle/file_id.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package needle
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
type FileId struct {
|
||||
VolumeId VolumeId
|
||||
Key NeedleId
|
||||
Cookie Cookie
|
||||
}
|
||||
|
||||
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 {
|
||||
return n.VolumeId.String() + "," + formatNeedleIdCookie(n.Key, n.Cookie)
|
||||
}
|
||||
|
||||
func formatNeedleIdCookie(key NeedleId, cookie Cookie) string {
|
||||
bytes := make([]byte, NeedleIdSize+CookieSize)
|
||||
NeedleIdToBytes(bytes[0:NeedleIdSize], key)
|
||||
CookieToBytes(bytes[NeedleIdSize:NeedleIdSize+CookieSize], cookie)
|
||||
nonzero_index := 0
|
||||
for ; bytes[nonzero_index] == 0; nonzero_index++ {
|
||||
}
|
||||
return hex.EncodeToString(bytes[nonzero_index:])
|
||||
}
|
Reference in New Issue
Block a user