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.

68 lines
1.4 KiB

  1. package filer_pb
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  4. )
  5. func toFileId(fileIdStr string) (*FileId, error) {
  6. t, err := needle.ParseFileIdFromString(fileIdStr)
  7. if err != nil {
  8. return nil, err
  9. }
  10. return &FileId{
  11. VolumeId: uint32(t.VolumeId),
  12. Cookie: uint32(t.Cookie),
  13. FileKey: uint64(t.Key),
  14. }, nil
  15. }
  16. func (fid *FileId) toFileId() string {
  17. return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String()
  18. }
  19. func ChunkEquals(this, that *FileChunk) bool {
  20. if this.Fid == nil{
  21. this.Fid, _ = toFileId(this.FileId)
  22. }
  23. if that.Fid == nil{
  24. that.Fid, _ = toFileId(that.FileId)
  25. }
  26. return this.Fid.FileKey == that.Fid.FileKey && this.Fid.VolumeId == that.Fid.VolumeId && this.Fid.Cookie == that.Fid.Cookie
  27. }
  28. func BeforeEntrySerialization(chunks []*FileChunk) {
  29. for _, chunk := range chunks {
  30. if chunk.FileId != "" {
  31. if fid, err := toFileId(chunk.FileId); err == nil {
  32. chunk.Fid = fid
  33. chunk.FileId = ""
  34. }
  35. }
  36. if chunk.SourceFileId != "" {
  37. if fid, err := toFileId(chunk.SourceFileId); err == nil {
  38. chunk.SourceFid = fid
  39. chunk.SourceFileId = ""
  40. }
  41. }
  42. }
  43. }
  44. func AfterEntryDeserialization(chunks []*FileChunk) {
  45. for _, chunk := range chunks {
  46. if chunk.Fid != nil && chunk.FileId == "" {
  47. chunk.FileId = chunk.Fid.toFileId()
  48. }
  49. if chunk.SourceFid != nil && chunk.SourceFileId == "" {
  50. chunk.SourceFileId = chunk.SourceFid.toFileId()
  51. }
  52. }
  53. }