From 4326ff56a7115382b8cbdc20063d28a5094ce8ac Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 16 Sep 2020 15:07:23 +0300 Subject: [PATCH] [#30] core/object: Remove redundant Address type Remove Address type. Makes Address method of the Object to return NeoFS SDK Address type. Makes local storage to work with NeoFS SDK object address. Signed-off-by: Leonard Lyubich --- pkg/core/object/address.go | 30 ------------------- pkg/core/object/object.go | 6 ++-- pkg/local_object_storage/localstore/meta.go | 2 +- .../localstore/methods.go | 15 +++++----- 4 files changed, 11 insertions(+), 42 deletions(-) delete mode 100644 pkg/core/object/address.go diff --git a/pkg/core/object/address.go b/pkg/core/object/address.go deleted file mode 100644 index 905e10535..000000000 --- a/pkg/core/object/address.go +++ /dev/null @@ -1,30 +0,0 @@ -package object - -import ( - "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/nspcc-dev/neofs-api-go/v2/refs" -) - -type Address struct { - *object.Address -} - -// MarshalStableV2 marshals Address to v2 binary format. -func (a *Address) MarshalStableV2() ([]byte, error) { - if a != nil { - return a.ToV2().StableMarshal(nil) - } - - return nil, nil -} - -// AddressFromV2 converts v2 Address message to Address. -func AddressFromV2(aV2 *refs.Address) *Address { - if aV2 == nil { - return nil - } - - return &Address{ - Address: object.NewAddressFromV2(aV2), - } -} diff --git a/pkg/core/object/object.go b/pkg/core/object/object.go index 5aebab87c..de272cc10 100644 --- a/pkg/core/object/object.go +++ b/pkg/core/object/object.go @@ -25,15 +25,13 @@ func (o *Object) MarshalStableV2() ([]byte, error) { } // Address returns address of the object. -func (o *Object) Address() *Address { +func (o *Object) Address() *object.Address { if o != nil { aV2 := new(refs.Address) aV2.SetObjectID(o.GetID().ToV2()) aV2.SetContainerID(o.GetContainerID().ToV2()) - return &Address{ - Address: object.NewAddressFromV2(aV2), - } + return object.NewAddressFromV2(aV2) } return nil diff --git a/pkg/local_object_storage/localstore/meta.go b/pkg/local_object_storage/localstore/meta.go index 27835d9c3..a8eccdd38 100644 --- a/pkg/local_object_storage/localstore/meta.go +++ b/pkg/local_object_storage/localstore/meta.go @@ -37,7 +37,7 @@ func (m *ObjectMeta) Head() *object.Object { } // AddressFromMeta extracts the Address from object meta. -func AddressFromMeta(m *ObjectMeta) *object.Address { +func AddressFromMeta(m *ObjectMeta) *objectSDK.Address { return m.Head().Address() } diff --git a/pkg/local_object_storage/localstore/methods.go b/pkg/local_object_storage/localstore/methods.go index 39521abbd..94625f727 100644 --- a/pkg/local_object_storage/localstore/methods.go +++ b/pkg/local_object_storage/localstore/methods.go @@ -3,13 +3,14 @@ package localstore import ( "context" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/pkg/errors" "go.uber.org/zap" ) func (s *Storage) Put(obj *object.Object) error { - addrBytes, err := obj.Address().MarshalStableV2() + addrBytes, err := obj.Address().ToV2().StableMarshal(nil) if err != nil { return errors.Wrap(err, "could not marshal object address") } @@ -35,8 +36,8 @@ func (s *Storage) Put(obj *object.Object) error { return nil } -func (s *Storage) Delete(addr *object.Address) error { - addrBytes, err := addr.MarshalStableV2() +func (s *Storage) Delete(addr *objectSDK.Address) error { + addrBytes, err := addr.ToV2().StableMarshal(nil) if err != nil { return errors.Wrap(err, "could not marshal object address") } @@ -54,8 +55,8 @@ func (s *Storage) Delete(addr *object.Address) error { return nil } -func (s *Storage) Get(addr *object.Address) (*object.Object, error) { - addrBytes, err := addr.MarshalStableV2() +func (s *Storage) Get(addr *objectSDK.Address) (*object.Object, error) { + addrBytes, err := addr.ToV2().StableMarshal(nil) if err != nil { return nil, errors.Wrap(err, "could not marshal object address") } @@ -68,8 +69,8 @@ func (s *Storage) Get(addr *object.Address) (*object.Object, error) { return object.FromBytes(objBytes) } -func (s *Storage) Head(addr *object.Address) (*ObjectMeta, error) { - addrBytes, err := addr.MarshalStableV2() +func (s *Storage) Head(addr *objectSDK.Address) (*ObjectMeta, error) { + addrBytes, err := addr.ToV2().StableMarshal(nil) if err != nil { return nil, errors.Wrap(err, "could not marshal object address") }