From 2aacaa6aba3a74ed11443b5fd76e9982964e42a5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 5 Apr 2022 11:33:36 +0300 Subject: [PATCH] refs: optimize marshalin of `[]ObjectID` Signed-off-by: Evgenii Stratonikov --- refs/marshal.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/refs/marshal.go b/refs/marshal.go index 0a17a51..dc8517f 100644 --- a/refs/marshal.go +++ b/refs/marshal.go @@ -1,6 +1,8 @@ package refs import ( + "encoding/binary" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" "github.com/nspcc-dev/neofs-api-go/v2/rpc/message" "github.com/nspcc-dev/neofs-api-go/v2/util/proto" @@ -114,8 +116,13 @@ func (o *ObjectID) StableSize() int { // ObjectIDNestedListMarshal writes protobuf repeated ObjectID field // with fNum number to buf. func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) { + prefix, _ := proto.NestedStructurePrefix(fNum) for i := range ids { - off += proto.NestedStructureMarshal(fNum, buf[off:], &ids[i]) + off += binary.PutUvarint(buf, prefix) + + n := ids[i].StableSize() + off += binary.PutUvarint(buf[off:], uint64(n)) + off += proto.BytesMarshal(objectIDValField, buf, ids[i].val) } return