[#233] v2/refs: Implement converters for object ID list type

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-21 10:51:45 +03:00
parent 51e8e318c2
commit 3039aa20c7
6 changed files with 85 additions and 68 deletions

View file

@ -3,6 +3,7 @@ package object
import (
"github.com/nspcc-dev/neofs-api-go/util/proto"
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
goproto "google.golang.org/protobuf/proto"
)
@ -295,15 +296,13 @@ func (h *SplitHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range h.children {
n, err = proto.NestedStructureMarshal(splitHdrChildrenField, buf[offset:], h.children[i])
if err != nil {
return nil, err
}
offset += n
n, err = refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf[offset:], h.children)
if err != nil {
return nil, err
}
offset += n
_, err = proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
if err != nil {
return nil, err
@ -321,11 +320,7 @@ func (h *SplitHeader) StableSize() (size int) {
size += proto.NestedStructureSize(splitHdrPreviousField, h.prev)
size += proto.NestedStructureSize(splitHdrParentSignatureField, h.parSig)
size += proto.NestedStructureSize(splitHdrParentHeaderField, h.parHdr)
for i := range h.children {
size += proto.NestedStructureSize(splitHdrChildrenField, h.children[i])
}
size += refs.ObjectIDNestedListSize(splitHdrChildrenField, h.children)
size += proto.BytesSize(splitHdrSplitIDField, h.splitID)
return size
@ -1227,17 +1222,13 @@ func (r *SearchResponseBody) StableMarshal(buf []byte) ([]byte, error) {
}
var (
offset, n int
err error
offset int
err error
)
for i := range r.idList {
n, err = proto.NestedStructureMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList[i])
if err != nil {
return nil, err
}
offset += n
_, err = refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList)
if err != nil {
return nil, err
}
return buf, nil
@ -1248,9 +1239,7 @@ func (r *SearchResponseBody) StableSize() (size int) {
return 0
}
for i := range r.idList {
size += proto.NestedStructureSize(searchRespBodyObjectIDsField, r.idList[i])
}
size += refs.ObjectIDNestedListSize(searchRespBodyObjectIDsField, r.idList)
return size
}