frostfs-node/pkg/services/object/get/v2/streamer.go
Airat Arifullin 9b13a18aac [#1479] go.mod: Bump frostfs-sdk-go version
* Update version within go.mod;
* Fix deprecated frostfs-api-go/v2 package and use frostfs-sdk-go/api
  instead.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-11-08 10:43:19 +03:00

64 lines
1.5 KiB
Go

package getsvc
import (
"context"
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
)
type streamObjectWriter struct {
objectSvc.GetObjectStream
}
type streamObjectRangeWriter struct {
objectSvc.GetObjectRangeStream
}
func (s *streamObjectWriter) WriteHeader(_ context.Context, obj *objectSDK.Object) error {
p := new(objectV2.GetObjectPartInit)
objV2 := obj.ToV2()
p.SetObjectID(objV2.GetObjectID())
p.SetHeader(objV2.GetHeader())
p.SetSignature(objV2.GetSignature())
return s.GetObjectStream.Send(newResponse(p))
}
func (s *streamObjectWriter) WriteChunk(_ context.Context, chunk []byte) error {
p := new(objectV2.GetObjectPartChunk)
p.SetChunk(chunk)
return s.GetObjectStream.Send(newResponse(p))
}
func newResponse(p objectV2.GetObjectPart) *objectV2.GetResponse {
r := new(objectV2.GetResponse)
body := new(objectV2.GetResponseBody)
r.SetBody(body)
body.SetObjectPart(p)
return r
}
func (s *streamObjectRangeWriter) WriteChunk(_ context.Context, chunk []byte) error {
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
}