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.

69 lines
1.3 KiB

  1. package filer_pb
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  4. )
  5. func toFileIdObject(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) toFileIdString() string {
  17. return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String()
  18. }
  19. func (c *FileChunk) GetFileIdString() string {
  20. if c.FileId != "" {
  21. return c.FileId
  22. }
  23. if c.Fid != nil {
  24. c.FileId = c.Fid.toFileIdString()
  25. return c.FileId
  26. }
  27. return ""
  28. }
  29. func BeforeEntrySerialization(chunks []*FileChunk) {
  30. for _, chunk := range chunks {
  31. if chunk.FileId != "" {
  32. if fid, err := toFileIdObject(chunk.FileId); err == nil {
  33. chunk.Fid = fid
  34. chunk.FileId = ""
  35. }
  36. }
  37. if chunk.SourceFileId != "" {
  38. if fid, err := toFileIdObject(chunk.SourceFileId); err == nil {
  39. chunk.SourceFid = fid
  40. chunk.SourceFileId = ""
  41. }
  42. }
  43. }
  44. }
  45. func AfterEntryDeserialization(chunks []*FileChunk) {
  46. for _, chunk := range chunks {
  47. if chunk.Fid != nil && chunk.FileId == "" {
  48. chunk.FileId = chunk.Fid.toFileIdString()
  49. }
  50. if chunk.SourceFid != nil && chunk.SourceFileId == "" {
  51. chunk.SourceFileId = chunk.SourceFid.toFileIdString()
  52. }
  53. }
  54. }