2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-09 08:02:27 +00:00
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-09-26 07:54:03 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
type streamObjectWriter struct {
|
|
|
|
objectSvc.GetObjectStream
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
type streamObjectRangeWriter struct {
|
|
|
|
objectSvc.GetObjectRangeStream
|
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (s *streamObjectWriter) WriteHeader(_ context.Context, obj *object.Object) error {
|
2020-12-02 23:45:25 +00:00
|
|
|
p := new(objectV2.GetObjectPartInit)
|
|
|
|
|
|
|
|
objV2 := obj.ToV2()
|
|
|
|
p.SetObjectID(objV2.GetObjectID())
|
|
|
|
p.SetHeader(objV2.GetHeader())
|
|
|
|
p.SetSignature(objV2.GetSignature())
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (s *streamObjectWriter) WriteChunk(_ context.Context, chunk []byte) error {
|
2020-12-02 23:45:25 +00:00
|
|
|
p := new(objectV2.GetObjectPartChunk)
|
|
|
|
p.SetChunk(chunk)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func newResponse(p objectV2.GetObjectPart) *objectV2.GetResponse {
|
|
|
|
r := new(objectV2.GetResponse)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
body := new(objectV2.GetResponseBody)
|
|
|
|
r.SetBody(body)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
body.SetObjectPart(p)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return r
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (s *streamObjectRangeWriter) WriteChunk(_ context.Context, chunk []byte) error {
|
2020-12-07 17:49:47 +00:00
|
|
|
return s.GetObjectRangeStream.Send(newRangeResponse(chunk))
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRangeResponse(p []byte) *objectV2.GetRangeResponse {
|
|
|
|
r := new(objectV2.GetRangeResponse)
|
|
|
|
|
|
|
|
body := new(objectV2.GetRangeResponseBody)
|
|
|
|
r.SetBody(body)
|
|
|
|
|
|
|
|
part := new(objectV2.GetRangePartChunk)
|
|
|
|
part.SetChunk(p)
|
|
|
|
|
|
|
|
body.SetRangePart(part)
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|