From 634e24aba71564e432c20a7fca787b23a19f5bf2 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 15 Feb 2024 15:38:48 +0300 Subject: [PATCH] [#65] object: Fix SetMarshalData for PutSingle request Allow to reset marshal data Signed-off-by: Dmitrii Stepanov --- object/marshal.go | 8 ++------ util/proto/marshal.go | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/object/marshal.go b/object/marshal.go index 7f47d65..ddd5746 100644 --- a/object/marshal.go +++ b/object/marshal.go @@ -1111,17 +1111,13 @@ func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte { // SetMarshalData sets marshal data to reduce memory allocations. // -// It is unsafe to modify request data after setting marshal data. +// It is unsafe to modify/copy request data after setting marshal data. func (r *PutSingleRequestBody) SetMarshalData(data []byte) { if r == nil { return } - if data == nil { - r.marshalData = r.StableMarshal(nil) - } else { - r.marshalData = data - } + r.marshalData = data proto.NestedStructureSetMarshalData(putSingleReqObjectField, r.marshalData, r.object) } diff --git a/util/proto/marshal.go b/util/proto/marshal.go index 768cb2b..26b3eb0 100644 --- a/util/proto/marshal.go +++ b/util/proto/marshal.go @@ -287,6 +287,11 @@ func NestedStructureSetMarshalData[T any, M setMarshalData[T]](field int64, pare return 0 } + if parentData == nil { + v.SetMarshalData(nil) + return 0 + } + n := v.StableSize() buf := make([]byte, binary.MaxVarintLen64) prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType) -- 2.45.2