forked from TrueCloudLab/frostfs-api-go
[#132] sdk/object: Implement useful methods and function
Implement method to get address of the object. Implement method to copy the object w/o payload. Implement function of object deserialization. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f18e8535c5
commit
acbdbd410e
1 changed files with 42 additions and 0 deletions
|
@ -77,6 +77,19 @@ func (o *Object) Verify() error {
|
||||||
return nil
|
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 {
|
func (o *Object) GetPayload() []byte {
|
||||||
if o != nil {
|
if o != nil {
|
||||||
return o.payload
|
return o.payload
|
||||||
|
@ -85,6 +98,25 @@ func (o *Object) GetPayload() []byte {
|
||||||
return nil
|
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.
|
// ToV2 converts object to v2 Object message.
|
||||||
func (o *Object) ToV2() *object.Object {
|
func (o *Object) ToV2() *object.Object {
|
||||||
obj, _ := o.rwObject.ToV2(nil)
|
obj, _ := o.rwObject.ToV2(nil)
|
||||||
|
@ -210,3 +242,13 @@ func FromV2(oV2 *object.Object) (*Object, error) {
|
||||||
},
|
},
|
||||||
}, nil
|
}, 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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue