frostfs-node/pkg/services/object/get/v2/streamer.go
Dmitrii Stepanov b8e93d4c08 [#85] get-service: Use assembler to assemble LOB
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-03-15 09:19:45 +03:00

64 lines
1.4 KiB
Go

package getsvc
import (
"context"
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"
)
type streamObjectWriter struct {
objectSvc.GetObjectStream
}
type streamObjectRangeWriter struct {
objectSvc.GetObjectRangeStream
}
func (s *streamObjectWriter) WriteHeader(_ context.Context, obj *object.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
}