2020-09-02 12:45:46 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
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"
|
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.
|
2020-09-16 12:07:23 +00:00
|
|
|
func (o *Object) Address() *object.Address {
|
2020-09-02 12:45:46 +00:00
|
|
|
if o != nil {
|
2020-09-16 11:58:58 +00:00
|
|
|
aV2 := new(refs.Address)
|
|
|
|
aV2.SetObjectID(o.GetID().ToV2())
|
|
|
|
aV2.SetContainerID(o.GetContainerID().ToV2())
|
|
|
|
|
2020-09-16 12:07:23 +00:00
|
|
|
return object.NewAddressFromV2(aV2)
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromV2 converts v2 Object message to Object.
|
2020-09-16 11:58:58 +00:00
|
|
|
func FromV2(oV2 *objectV2.Object) *Object {
|
2020-09-02 12:45:46 +00:00
|
|
|
if oV2 == nil {
|
2020-09-16 11:58:58 +00:00
|
|
|
return nil
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Object{
|
2020-09-16 11:58:58 +00:00
|
|
|
Object: object.NewFromV2(oV2),
|
|
|
|
}
|
2020-09-02 12:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FromBytes restores Object from binary format.
|
|
|
|
func FromBytes(data []byte) (*Object, error) {
|
|
|
|
o, err := object.FromBytes(data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Object{
|
|
|
|
Object: o,
|
|
|
|
}, nil
|
|
|
|
}
|