[#130] sdk: Define object types

Define Object type that represents the immutable NeoFS object. Define
RawObject type that provides interface for convenient construction of NeoFS
object.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-01 16:31:57 +03:00 committed by Stanislav Bogatyrev
parent a65db08608
commit 8c3f8268b9
2 changed files with 253 additions and 0 deletions

53
pkg/object/raw.go Normal file
View file

@ -0,0 +1,53 @@
package object
import (
"crypto/sha256"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
)
// RawObject represents NeoFS object that provides
// a convenient interface to fill in the fields of
// an object in isolation from its internal structure.
type RawObject struct {
rwObject
}
func (o *RawObject) set(setter func()) {
o.fin = false
setter()
}
// SetContainerID sets object's container identifier.
func (o *RawObject) SetContainerID(v *container.ID) {
if o != nil {
o.set(func() {
o.cid = v
})
}
}
// SetOwnerID sets identifier of the object's owner.
func (o *RawObject) SetOwnerID(v *owner.ID) {
if o != nil {
o.set(func() {
o.ownerID = v
})
}
}
// SetPayloadChecksumSHA256 sets payload checksum as a SHA256 checksum.
func (o *RawObject) SetPayloadChecksumSHA256(v [sha256.Size]byte) {
if o != nil {
o.set(func() {
if o.payloadChecksum == nil {
o.payloadChecksum = new(refs.Checksum)
}
o.payloadChecksum.SetType(refs.SHA256)
o.payloadChecksum.SetSum(v[:])
})
}
}