2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
|
|
|
)
|
|
|
|
|
|
|
|
type streamer struct {
|
|
|
|
stream *putsvc.Streamer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *streamer) Send(req *object.PutRequest) (err error) {
|
|
|
|
switch v := req.GetBody().GetObjectPart().(type) {
|
|
|
|
case *object.PutObjectPartInit:
|
2021-01-14 07:51:05 +00:00
|
|
|
var initPrm *putsvc.PutInitPrm
|
|
|
|
|
|
|
|
initPrm, err = toInitPrm(v, req)
|
2021-01-12 14:55:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = s.stream.Init(initPrm); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
err = fmt.Errorf("(%T) could not init object put stream: %w", s, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
case *object.PutObjectPartChunk:
|
|
|
|
if err = s.stream.SendChunk(toChunkPrm(v)); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
err = fmt.Errorf("(%T) could not send payload chunk: %w", s, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
default:
|
2021-05-18 08:12:51 +00:00
|
|
|
err = fmt.Errorf("(%T) invalid object put stream part type %T", s, v)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *streamer) CloseAndRecv() (*object.PutResponse, error) {
|
|
|
|
resp, err := s.stream.Close()
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("(%T) could not object put stream: %w", s, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fromPutResponse(resp), nil
|
|
|
|
}
|