From 6b0bd42f25369636fb28fa99f0b72cb95b6503a5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 24 Nov 2020 20:15:12 +0300 Subject: [PATCH] [#209] pkg/object: Support splitID field in SDK library Signed-off-by: Alex Vanin --- pkg/object/raw.go | 5 +++++ pkg/object/raw_test.go | 14 ++++++++++++++ pkg/object/rw.go | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/pkg/object/raw.go b/pkg/object/raw.go index 2615530f..5ae3108f 100644 --- a/pkg/object/raw.go +++ b/pkg/object/raw.go @@ -110,6 +110,11 @@ func (o *RawObject) SetChildren(v ...*ID) { o.setChildren(v...) } +// SetSplitID sets split identifier for the split object. +func (o *RawObject) SetSplitID(v []byte) { + o.setSplitID(v) +} + // SetParentID sets identifier of the parent object. func (o *RawObject) SetParentID(v *ID) { o.setParentID(v) diff --git a/pkg/object/raw_test.go b/pkg/object/raw_test.go index 2aabca4f..f6e85a87 100644 --- a/pkg/object/raw_test.go +++ b/pkg/object/raw_test.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "testing" + "github.com/google/uuid" "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" @@ -190,6 +191,19 @@ func TestRawObject_SetChildren(t *testing.T) { require.Equal(t, []*ID{id1, id2}, obj.Children()) } +func TestRawObject_SetSplitID(t *testing.T) { + obj := NewRaw() + + require.Nil(t, obj.SplitID()) + + splitID, err := uuid.New().MarshalBinary() + require.NoError(t, err) + + obj.SetSplitID(splitID) + + require.Equal(t, obj.SplitID(), splitID) +} + func TestRawObject_SetParent(t *testing.T) { obj := NewRaw() diff --git a/pkg/object/rw.go b/pkg/object/rw.go index e6be2e5c..0412f913 100644 --- a/pkg/object/rw.go +++ b/pkg/object/rw.go @@ -251,6 +251,21 @@ func (o *rwObject) setChildren(v ...*ID) { }) } +// SplitID return split identity of split object. If object is not split +// returns nil. +func (o *rwObject) SplitID() []byte { + return (*object.Object)(o). + GetHeader(). + GetSplit(). + GetSplitID() +} + +func (o *rwObject) setSplitID(id []byte) { + o.setSplitFields(func(split *object.SplitHeader) { + split.SetSplitID(id) + }) +} + // ParentID returns identifier of the parent object. func (o *rwObject) ParentID() *ID { return NewIDFromV2(