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.

58 lines
1.1 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 BeforeEntrySerialization(chunks []*FileChunk) {
  20. for _, chunk := range chunks {
  21. if chunk.FileId != "" {
  22. if fid, err := toFileId(chunk.FileId); err == nil {
  23. chunk.Fid = fid
  24. chunk.FileId = ""
  25. }
  26. }
  27. if chunk.SourceFileId != "" {
  28. if fid, err := toFileId(chunk.SourceFileId); err == nil {
  29. chunk.SourceFid = fid
  30. chunk.SourceFileId = ""
  31. }
  32. }
  33. }
  34. }
  35. func AfterEntryDeserialization(chunks []*FileChunk) {
  36. for _, chunk := range chunks {
  37. if chunk.Fid != nil && chunk.FileId == "" {
  38. chunk.FileId = chunk.Fid.toFileId()
  39. }
  40. if chunk.SourceFid != nil && chunk.SourceFileId == "" {
  41. chunk.SourceFileId = chunk.SourceFid.toFileId()
  42. }
  43. }
  44. }