diff --git a/pkg/object/object.go b/pkg/object/object.go index 22688dd5..be1f5b8b 100644 --- a/pkg/object/object.go +++ b/pkg/object/object.go @@ -77,6 +77,19 @@ func (o *Object) Verify() error { return nil } +// Address returns address of the object. +func (o *Object) Address() *Address { + if o != nil { + return &Address{ + cid: o.cid, + oid: o.id, + } + } + + return nil +} + +// GetPayload returns object payload bytes. func (o *Object) GetPayload() []byte { if o != nil { return o.payload @@ -85,6 +98,25 @@ func (o *Object) GetPayload() []byte { return nil } +// CutPayload copies object fields w/o payload. +func (o *Object) CutPayload() *Object { + if o != nil { + return &Object{ + rwObject: rwObject{ + fin: o.fin, + id: o.id, + key: o.key, + sig: o.sig, + cid: o.cid, + ownerID: o.ownerID, + payloadChecksum: o.payloadChecksum, + }, + } + } + + return nil +} + // ToV2 converts object to v2 Object message. func (o *Object) ToV2() *object.Object { obj, _ := o.rwObject.ToV2(nil) @@ -210,3 +242,13 @@ func FromV2(oV2 *object.Object) (*Object, error) { }, }, nil } + +// FromBytes restores Object from a binary representation. +func FromBytes(data []byte) (*Object, error) { + oV2 := new(object.Object) + if err := oV2.StableUnmarshal(data); err != nil { + return nil, errors.Wrap(err, "could not unmarshal object") + } + + return FromV2(oV2) +}