2020-09-01 13:31:57 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
)
|
|
|
|
|
2020-09-10 13:11:12 +00:00
|
|
|
// Object represents v2-compatible NeoFS object that provides
|
2020-09-01 13:31:57 +00:00
|
|
|
// a convenient interface for working in isolation
|
|
|
|
// from the internal structure of an object.
|
|
|
|
//
|
|
|
|
// Object allows to work with the object in read-only
|
|
|
|
// mode as a reflection of the immutability of objects
|
|
|
|
// in the system.
|
|
|
|
type Object struct {
|
2020-09-10 13:11:12 +00:00
|
|
|
*rwObject
|
2020-09-01 13:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 13:11:12 +00:00
|
|
|
// NewFromV2 wraps v2 Object message to Object.
|
|
|
|
func NewFromV2(oV2 *object.Object) *Object {
|
|
|
|
return &Object{
|
|
|
|
rwObject: (*rwObject)(oV2),
|
2020-09-01 13:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:11:12 +00:00
|
|
|
// New creates and initializes blank Object.
|
|
|
|
//
|
|
|
|
// Works similar as NewFromV2(new(Object)).
|
|
|
|
func New() *Object {
|
2020-09-16 11:16:58 +00:00
|
|
|
return NewFromV2(new(object.Object))
|
2020-09-02 11:48:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 13:11:12 +00:00
|
|
|
// ToV2 converts Object to v2 Object message.
|
|
|
|
func (o *Object) ToV2() *object.Object {
|
2020-09-02 11:51:29 +00:00
|
|
|
if o != nil {
|
2020-09-10 13:11:12 +00:00
|
|
|
return (*object.Object)(o.rwObject)
|
2020-09-02 11:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-07 10:43:14 +00:00
|
|
|
|
|
|
|
// MarshalHeaderJSON marshals object's header
|
|
|
|
// into JSON format.
|
|
|
|
func (o *Object) MarshalHeaderJSON() ([]byte, error) {
|
|
|
|
return (*object.Object)(o.rwObject).GetHeader().MarshalJSON()
|
|
|
|
}
|