Skip to content

Commit 9239cb9

Browse files
committed
Reuse gRPC codec from SDK
Signed-off-by: Leonard Liubich <leonard@morphbits.io>
1 parent cc612ba commit 9239cb9

1 file changed

Lines changed: 1 addition & 26 deletions

File tree

pkg/services/object/put/remote.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
protostatus "github.com/nspcc-dev/neofs-sdk-go/proto/status"
2323
"github.com/nspcc-dev/neofs-sdk-go/user"
2424
"google.golang.org/grpc"
25-
"google.golang.org/grpc/encoding"
26-
"google.golang.org/grpc/encoding/proto"
2725
"google.golang.org/grpc/mem"
2826
)
2927

@@ -134,7 +132,7 @@ func sendReplicationRequestToNode(ctx context.Context, conn clientcore.MultiAddr
134132
// this will be changed during NeoFS API Go deprecation. Code most likely be
135133
// placed in SDK
136134
var resp protoobject.ReplicateResponse
137-
err := conn.Invoke(ctx, protoobject.ObjectService_Replicate_FullMethodName, req, &resp, binaryMessageOnly)
135+
err := conn.Invoke(ctx, protoobject.ObjectService_Replicate_FullMethodName, mem.SliceBuffer(req), &resp, grpc.ForceCodecV2(protobuf.BufferedCodec{}))
138136
if err != nil {
139137
return newAPICallError(protoobject.ObjectService_Replicate_FullMethodName, err)
140138
}
@@ -241,29 +239,6 @@ func sendReplicationV2RequestToNode(ctx context.Context, signer neofscrypto.Sign
241239
return res, err
242240
}
243241

244-
// [encoding.Codec] making Marshal to accept and forward []byte messages only.
245-
var binaryMessageOnly = grpc.ForceCodecV2(protoCodecBinaryRequestOnly{})
246-
247-
type protoCodecBinaryRequestOnly struct{}
248-
249-
func (protoCodecBinaryRequestOnly) Name() string {
250-
// may be any non-empty, conflicts are unlikely to arise
251-
return "neofs_binary_sender"
252-
}
253-
254-
func (protoCodecBinaryRequestOnly) Marshal(msg any) (mem.BufferSlice, error) {
255-
bMsg, ok := msg.([]byte)
256-
if ok {
257-
return mem.BufferSlice{mem.SliceBuffer(bMsg)}, nil
258-
}
259-
260-
return nil, fmt.Errorf("message is not of type %T", bMsg)
261-
}
262-
263-
func (protoCodecBinaryRequestOnly) Unmarshal(data mem.BufferSlice, msg any) error {
264-
return encoding.GetCodecV2(proto.Name).Unmarshal(data, msg)
265-
}
266-
267242
func newAPICallError(method string, cause error) error {
268243
return fmt.Errorf("API transport (op=%s): %w", method, cause)
269244
}

0 commit comments

Comments
 (0)