2020-09-02 12:45:46 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-09-16 11:58:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-09-02 12:45:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Object represents the NeoFS object.
|
|
|
|
//
|
|
|
|
// Object inherits object type from NeoFS SDK.
|
|
|
|
// It is used to implement some useful methods and functions
|
|
|
|
// for convenient processing of an object by a node.
|
|
|
|
type Object struct {
|
|
|
|
*object.Object
|
|
|
|
}
|
|
|
|
|
|
|
|
// Address returns address of the object.
|
2022-01-26 12:11:13 +00:00
|
|
|
func (o *Object) Address() *addressSDK.Address {
|
2020-09-02 12:45:46 +00:00
|
|
|
if o != nil {
|
2020-09-16 11:58:58 +00:00
|
|
|
aV2 := new(refs.Address)
|
2020-11-16 09:43:52 +00:00
|
|
|
aV2.SetObjectID(o.ID().ToV2())
|
|
|
|
aV2.SetContainerID(o.ContainerID().ToV2())
|
2020-09-16 11:58:58 +00:00
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
return addressSDK.NewAddressFromV2(aV2)
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:25:03 +00:00
|
|
|
// SDK returns NeoFS SDK object instance.
|
|
|
|
func (o *Object) SDK() *object.Object {
|
|
|
|
if o != nil {
|
|
|
|
return o.Object
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-16 12:27:48 +00:00
|
|
|
// NewFromV2 constructs Object instance from v2 Object message.
|
|
|
|
func NewFromV2(obj *objectV2.Object) *Object {
|
|
|
|
return &Object{
|
|
|
|
Object: object.NewFromV2(obj),
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
2020-09-16 12:27:48 +00:00
|
|
|
}
|
2020-09-02 12:45:46 +00:00
|
|
|
|
2020-09-16 12:27:48 +00:00
|
|
|
// NewFromSDK constructs Object instance from NeoFS SDK Object.
|
|
|
|
func NewFromSDK(obj *object.Object) *Object {
|
2020-09-02 12:45:46 +00:00
|
|
|
return &Object{
|
2020-09-16 12:27:48 +00:00
|
|
|
Object: obj,
|
2020-09-16 11:58:58 +00:00
|
|
|
}
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 12:27:48 +00:00
|
|
|
// New constructs blank Object instance.
|
|
|
|
func New() *Object {
|
|
|
|
return NewFromSDK(object.New())
|
|
|
|
}
|
|
|
|
|
2020-10-01 11:42:17 +00:00
|
|
|
// GetParent returns parent object.
|
|
|
|
func (o *Object) GetParent() *Object {
|
|
|
|
if o != nil {
|
2020-11-16 09:43:52 +00:00
|
|
|
if par := o.Object.Parent(); par != nil {
|
2020-10-01 11:42:17 +00:00
|
|
|
return &Object{
|
|
|
|
Object: par,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|