diff --git a/pkg/object/address.go b/pkg/object/address.go index af8271a4..0c50e4f0 100644 --- a/pkg/object/address.go +++ b/pkg/object/address.go @@ -1,6 +1,7 @@ package object import ( + "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/pkg/errors" ) @@ -34,3 +35,27 @@ func AddressFromBytes(data []byte) (*Address, error) { return NewAddressFromV2(addrV2), nil } + +// GetContainerID returns container identifier. +func (a *Address) GetContainerID() *container.ID { + return container.NewIDFromV2( + (*refs.Address)(a).GetContainerID(), + ) +} + +// SetContainerID sets container identifier. +func (a *Address) SetContainerID(id *container.ID) { + (*refs.Address)(a).SetContainerID(id.ToV2()) +} + +// GetObjectID returns object identifier. +func (a *Address) GetObjectID() *ID { + return NewIDFromV2( + (*refs.Address)(a).GetObjectID(), + ) +} + +// SetObjectID sets object identifier. +func (a *Address) SetObjectID(id *ID) { + (*refs.Address)(a).SetObjectID(id.ToV2()) +} diff --git a/pkg/object/address_test.go b/pkg/object/address_test.go new file mode 100644 index 00000000..d286ed48 --- /dev/null +++ b/pkg/object/address_test.go @@ -0,0 +1,29 @@ +package object + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/pkg/container" + "github.com/stretchr/testify/require" +) + +func TestAddress_SetContainerID(t *testing.T) { + a := NewAddress() + + cid := container.NewID() + cid.SetSHA256(randSHA256Checksum(t)) + + a.SetContainerID(cid) + + require.Equal(t, cid, a.GetContainerID()) +} + +func TestAddress_SetObjectID(t *testing.T) { + a := NewAddress() + + oid := randID(t) + + a.SetObjectID(oid) + + require.Equal(t, oid, a.GetObjectID()) +}