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.

37 lines
962 B

13 years ago
  1. package storage
  2. import (
  3. "code.google.com/p/weed-fs/go/util"
  4. "encoding/hex"
  5. "strings"
  6. )
  7. type FileId struct {
  8. VolumeId VolumeId
  9. Key uint64
  10. Hashcode uint32
  11. }
  12. func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId {
  13. return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
  14. }
  15. func ParseFileId(fid string) *FileId {
  16. a := strings.Split(fid, ",")
  17. if len(a) != 2 {
  18. println("Invalid fid", fid, ", split length", len(a))
  19. return nil
  20. }
  21. vid_string, key_hash_string := a[0], a[1]
  22. volumeId, _ := NewVolumeId(vid_string)
  23. key, hash := ParseKeyHash(key_hash_string)
  24. return &FileId{VolumeId: volumeId, Key: key, Hashcode: hash}
  25. }
  26. func (n *FileId) String() string {
  27. bytes := make([]byte, 12)
  28. util.Uint64toBytes(bytes[0:8], n.Key)
  29. util.Uint32toBytes(bytes[8:12], n.Hashcode)
  30. nonzero_index := 0
  31. for ; bytes[nonzero_index] == 0; nonzero_index++ {
  32. }
  33. return n.VolumeId.String() + "," + hex.EncodeToString(bytes[nonzero_index:])
  34. }