diff --git a/pkg/object/raw.go b/pkg/object/raw.go index 6930b6a..0ff3ca0 100644 --- a/pkg/object/raw.go +++ b/pkg/object/raw.go @@ -120,3 +120,16 @@ func (o *RawObject) SetSessionToken(v *token.SessionToken) { func (o *RawObject) SetType(v Type) { o.setType(v) } + +// CutPayload returns RawObject w/ empty payload. +// +// Changes of non-payload fields affect source object. +func (o *RawObject) CutPayload() *RawObject { + if o != nil { + return &RawObject{ + rwObject: o.rwObject.cutPayload(), + } + } + + return nil +} diff --git a/pkg/object/raw_test.go b/pkg/object/raw_test.go index 531789a..ec5563e 100644 --- a/pkg/object/raw_test.go +++ b/pkg/object/raw_test.go @@ -224,3 +224,30 @@ func TestRawObject_SetType(t *testing.T) { require.Equal(t, typ, obj.GetType()) } + +func TestRawObject_CutPayload(t *testing.T) { + o1 := NewRaw() + + p1 := []byte{12, 3} + o1.SetPayload(p1) + + sz := uint64(13) + o1.SetPayloadSize(sz) + + o2 := o1.CutPayload() + + require.Equal(t, sz, o2.GetPayloadSize()) + require.Empty(t, o2.GetPayload()) + + sz++ + o1.SetPayloadSize(sz) + + require.Equal(t, sz, o1.GetPayloadSize()) + require.Equal(t, sz, o2.GetPayloadSize()) + + p2 := []byte{4, 5, 6} + o2.SetPayload(p2) + + require.Equal(t, p2, o2.GetPayload()) + require.Equal(t, p1, o1.GetPayload()) +} diff --git a/pkg/object/rw.go b/pkg/object/rw.go index e2575d7..bb3f2c0 100644 --- a/pkg/object/rw.go +++ b/pkg/object/rw.go @@ -303,3 +303,11 @@ func (o *rwObject) setType(t Type) { h.SetObjectType(t.ToV2()) }) } + +func (o *rwObject) cutPayload() *rwObject { + ov2 := new(object.Object) + *ov2 = *(*object.Object)(o) + ov2.SetPayload(nil) + + return (*rwObject)(ov2) +}