From 8580b49c8d65a78126444ef49df1bbb18a849a42 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 24 Jul 2024 17:45:30 +0300 Subject: [PATCH] [#94] rpc: Introduce `ObjectService.Patch` method Signed-off-by: Airat Arifullin --- object/marshal.go | 6 +++--- rpc/object.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/object/marshal.go b/object/marshal.go index a0b82df..00bafc9 100644 --- a/object/marshal.go +++ b/object/marshal.go @@ -1336,7 +1336,7 @@ func (r *PatchRequestBodyPatch) StableMarshal(buf []byte) []byte { var offset int offset += proto.NestedStructureMarshal(patchRequestBodyPatchRangeField, buf[offset:], r.Range) - offset += proto.BytesMarshal(patchRequestBodyPatchChunkField, buf[offset:], r.Chunk) + proto.BytesMarshal(patchRequestBodyPatchChunkField, buf[offset:], r.Chunk) return buf } @@ -1372,7 +1372,7 @@ func (r *PatchRequestBody) StableMarshal(buf []byte) []byte { offset += proto.NestedStructureMarshal(patchRequestBodyNewAttrsField, buf[offset:], &r.NewAttributes[i]) } offset += proto.BoolMarshal(patchRequestBodyReplaceAttrField, buf[offset:], r.ReplaceAttributes) - offset += proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.Patch) + proto.NestedStructureMarshal(patchRequestBodyPatchField, buf[offset:], r.Patch) return buf } @@ -1418,7 +1418,7 @@ func (r *PatchResponseBody) StableMarshal(buf []byte) []byte { } var offset int - offset += proto.NestedStructureMarshal(patchResponseBodyObjectIDField, buf[offset:], r.ObjectID) + proto.NestedStructureMarshal(patchResponseBodyObjectIDField, buf[offset:], r.ObjectID) return buf } diff --git a/rpc/object.go b/rpc/object.go index 1eca922..6d7af31 100644 --- a/rpc/object.go +++ b/rpc/object.go @@ -18,6 +18,7 @@ const ( rpcObjectHead = "Head" rpcObjectDelete = "Delete" rpcObjectPutSingle = "PutSingle" + rpcObjectPatch = "Patch" ) // PutRequestWriter is an object.PutRequest @@ -205,3 +206,38 @@ func PutSingleObject( return resp, nil } + +// PatchRequestWriter is an object.PatchRequest +// message streaming component. +type PatchRequestWriter struct { + wc client.MessageWriterCloser + + resp message.Message +} + +// Write writes req to the stream. +func (w *PatchRequestWriter) Write(req *object.PatchRequest) error { + return w.wc.WriteMessage(req) +} + +// Close closes the stream. +func (w *PatchRequestWriter) Close() error { + return w.wc.Close() +} + +// Patch executes ObjectService.Patch RPC. +func Patch( + cli *client.Client, + resp *object.PatchResponse, + opts ...client.CallOption, +) (*PatchRequestWriter, error) { + wc, err := client.OpenClientStream(cli, common.CallMethodInfoClientStream(serviceObject, rpcObjectPatch), resp, opts...) + if err != nil { + return nil, err + } + + return &PatchRequestWriter{ + wc: wc, + resp: resp, + }, nil +}