server: fix json marshalling of downloadBlobPart (#6108)

This commit is contained in:
Blake Mizerany 2024-07-31 16:01:24 -07:00 committed by GitHub
parent c4c84b7a0d
commit dc77bbcfa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,6 +61,36 @@ type blobDownloadPart struct {
*blobDownload `json:"-"` *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 ( const (
numDownloadParts = 64 numDownloadParts = 64
minDownloadPartSize int64 = 100 * format.MegaByte minDownloadPartSize int64 = 100 * format.MegaByte