[#164] sdk/object: Add parent ID getter and setter

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-30 18:39:27 +03:00 committed by Leonard Lyubich
parent 420d956062
commit ae81f4584e
3 changed files with 30 additions and 0 deletions

View file

@ -110,6 +110,11 @@ func (o *RawObject) SetChildren(v ...*ID) {
o.setChildren(v...) o.setChildren(v...)
} }
// SetParentID sets identifier of the parent object.
func (o *RawObject) SetParentID(v *ID) {
o.setParentID(v)
}
// SetParent sets parent object w/o payload. // SetParent sets parent object w/o payload.
func (o *RawObject) SetParent(v *Object) { func (o *RawObject) SetParent(v *Object) {
o.setParent(v) o.setParent(v)

View file

@ -251,3 +251,12 @@ func TestRawObject_CutPayload(t *testing.T) {
require.Equal(t, p2, o2.GetPayload()) require.Equal(t, p2, o2.GetPayload())
require.Equal(t, p1, o1.GetPayload()) require.Equal(t, p1, o1.GetPayload())
} }
func TestRawObject_SetParentID(t *testing.T) {
obj := NewRaw()
id := randID(t)
obj.setParentID(id)
require.Equal(t, id, obj.GetParentID())
}

View file

@ -251,6 +251,22 @@ func (o *rwObject) setChildren(v ...*ID) {
}) })
} }
// GetParentID returns identifier of the parent object.
func (o *rwObject) GetParentID() *ID {
return NewIDFromV2(
(*object.Object)(o).
GetHeader().
GetSplit().
GetParent(),
)
}
func (o *rwObject) setParentID(v *ID) {
o.setSplitFields(func(split *object.SplitHeader) {
split.SetParent(v.ToV2())
})
}
// GetParent returns parent object w/o payload. // GetParent returns parent object w/o payload.
func (o *rwObject) GetParent() *Object { func (o *rwObject) GetParent() *Object {
h := (*object.Object)(o). h := (*object.Object)(o).