You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
946 B

11 years ago
  1. package storage
  2. import (
  3. "encoding/hex"
  4. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  5. )
  6. type FileId struct {
  7. VolumeId VolumeId
  8. Key NeedleId
  9. Cookie Cookie
  10. }
  11. func NewFileIdFromNeedle(VolumeId VolumeId, n *Needle) *FileId {
  12. return &FileId{VolumeId: VolumeId, Key: n.Id, Cookie: n.Cookie}
  13. }
  14. func NewFileId(VolumeId VolumeId, key uint64, cookie uint32) *FileId {
  15. return &FileId{VolumeId: VolumeId, Key: Uint64ToNeedleId(key), Cookie: Uint32ToCookie(cookie)}
  16. }
  17. func (n *FileId) String() string {
  18. return n.VolumeId.String() + "," + formatNeedleIdCookie(n.Key, n.Cookie)
  19. }
  20. func formatNeedleIdCookie(key NeedleId, cookie Cookie) string {
  21. bytes := make([]byte, NeedleIdSize+CookieSize)
  22. NeedleIdToBytes(bytes[0:NeedleIdSize], key)
  23. CookieToBytes(bytes[NeedleIdSize:NeedleIdSize+CookieSize], cookie)
  24. nonzero_index := 0
  25. for ; bytes[nonzero_index] == 0; nonzero_index++ {
  26. }
  27. return hex.EncodeToString(bytes[nonzero_index:])
  28. }