Skip to content

Commit

Permalink
rpc/object: Support binary transmission of ObjectService.Put messages
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Nov 23, 2023
1 parent c541c27 commit f6f2fd8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions rpc/object.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rpc

import (
"context"

"github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-api-go/v2/rpc/common"
Expand Down Expand Up @@ -54,6 +56,40 @@ func PutObject(
}, nil
}

// PutRequestBinaryWriter represents stream of binary-encoded request messages
// of the NeoFS API V2 ObjectService.Put RPC.
type PutRequestBinaryWriter struct {
wc client.MessageWriterCloser
}

// Write writes next binary-encoded request message to the stream. Note that
// message sequence and format should comply to the protocol requirements.
func (w *PutRequestBinaryWriter) Write(msg []byte) error {
return w.wc.WriteMessage(client.BinaryMessage(msg))
}

// Close closes the stream and decodes response message.
func (w *PutRequestBinaryWriter) Close() error {
return w.wc.Close()
}

// PutObjectBinary opens and returns binary object stream using NeoFS API V2
// ObjectService.Put RPC. Object is transmitted by sequentially calling
// [PutRequestBinaryWriter.Write] method. When stream is completed,
// [PutRequestBinaryWriter.Close] must be called. If transmission succeeds,
// provided response is decoded from the received message.
func PutObjectBinary(ctx context.Context, cli *client.Client, resp *object.PutResponse, opts ...client.CallOption) (*PutRequestBinaryWriter, error) {
wc, err := client.OpenClientStream(cli, common.CallMethodInfoClientStream(serviceObject, rpcObjectPut), resp,
append(opts, client.WithContext(ctx), client.AllowBinarySendingOnly())...)
if err != nil {
return nil, err
}

return &PutRequestBinaryWriter{
wc: wc,
}, nil
}

// GetResponseReader is an object.GetResponse
// stream reader.
type GetResponseReader struct {
Expand Down

0 comments on commit f6f2fd8

Please sign in to comment.