forked from TrueCloudLab/frostfs-node
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
8366c146d7
commit
4326ff56a7
4 changed files with 11 additions and 42 deletions
|
@ -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),
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue