From dc77bbcfa40dea8b8fc7713a2ecacbc6a9d08a25 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Wed, 31 Jul 2024 16:01:24 -0700 Subject: [PATCH] server: fix json marshalling of downloadBlobPart (#6108) --- server/download.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/download.go b/server/download.go index 45483ba6..10074554 100644 --- a/server/download.go +++ b/server/download.go @@ -61,6 +61,36 @@ type blobDownloadPart struct { *blobDownload `json:"-"` } +type jsonBlobDownloadPart struct { + N int + Offset int64 + Size int64 + Completed int64 +} + +func (p *blobDownloadPart) MarshalJSON() ([]byte, error) { + return json.Marshal(jsonBlobDownloadPart{ + N: p.N, + Offset: p.Offset, + Size: p.Size, + Completed: p.Completed.Load(), + }) +} + +func (p *blobDownloadPart) UnmarshalJSON(b []byte) error { + var j jsonBlobDownloadPart + if err := json.Unmarshal(b, &j); err != nil { + return err + } + *p = blobDownloadPart{ + N: j.N, + Offset: j.Offset, + Size: j.Size, + } + p.Completed.Store(j.Completed) + return nil +} + const ( numDownloadParts = 64 minDownloadPartSize int64 = 100 * format.MegaByte