frostfs-sdk-go/object/split_header.go
Airat Arifullin 76265fe9be [#349] object: Introduce SplitHeader type
* Also introduce `SplitHeader` getter and `SetSplitHeader` setter
  for `Object` type.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2025-03-26 13:17:37 +03:00

124 lines
3.1 KiB
Go

package object
import (
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
// SplitHeader is an object's header component that defines the relationship
// between this object and other objects if the object is part of a split operation.
type SplitHeader object.SplitHeader
// NewSplitHeaderFromV2 wraps v2 SplitHeader message to SplitHeader.
func NewSplitHeaderFromV2(v2 *object.SplitHeader) *SplitHeader {
return (*SplitHeader)(v2)
}
// NewSplitHeader creates blank SplitHeader instance.
func NewSplitHeader() *SplitHeader {
return NewSplitHeaderFromV2(new(object.SplitHeader))
}
func (sh *SplitHeader) ToV2() *object.SplitHeader {
return (*object.SplitHeader)(sh)
}
func (sh *SplitHeader) ParentID() (v oid.ID, isSet bool) {
v2 := (*object.SplitHeader)(sh)
if id := v2.GetParent(); id != nil {
_ = v.ReadFromV2(*id)
isSet = true
}
return
}
func (sh *SplitHeader) SetParentID(v oid.ID) {
v2 := new(refs.ObjectID)
v.WriteToV2(v2)
(*object.SplitHeader)(sh).SetParent(v2)
}
func (sh *SplitHeader) PreviousID() (v oid.ID, isSet bool) {
v2 := (*object.SplitHeader)(sh)
if id := v2.GetPrevious(); id != nil {
_ = v.ReadFromV2(*id)
isSet = true
}
return
}
func (sh *SplitHeader) SetPreviousID(v oid.ID) {
v2 := new(refs.ObjectID)
v.WriteToV2(v2)
(*object.SplitHeader)(sh).SetPrevious(v2)
}
func (sh *SplitHeader) ParentSignature() *frostfscrypto.Signature {
v2 := (*object.SplitHeader)(sh)
if parSigV2 := v2.GetParentSignature(); parSigV2 != nil {
parSig := new(frostfscrypto.Signature)
_ = parSig.ReadFromV2(*parSigV2)
}
return nil
}
func (sh *SplitHeader) SetParentSignature(v *frostfscrypto.Signature) {
var parSigV2 *refs.Signature
if v != nil {
parSigV2 = new(refs.Signature)
v.WriteToV2(parSigV2)
}
(*object.SplitHeader)(sh).SetParentSignature(parSigV2)
}
func (sh *SplitHeader) ParentHeader() (parentHeader *Object) {
v2 := (*object.SplitHeader)(sh)
if parHdr := v2.GetParentHeader(); parHdr != nil {
parentHeader = New()
parentHeader.setHeaderField(func(h *object.Header) {
*h = *v2.GetParentHeader()
})
}
return
}
func (sh *SplitHeader) SetParentHeader(parentHeader *Object) {
(*object.SplitHeader)(sh).SetParentHeader(parentHeader.ToV2().GetHeader())
}
func (sh *SplitHeader) Children() (res []oid.ID) {
v2 := (*object.SplitHeader)(sh)
if children := v2.GetChildren(); len(children) > 0 {
res = make([]oid.ID, len(children))
for i := range children {
_ = res[i].ReadFromV2(children[i])
}
}
return
}
func (sh *SplitHeader) SetChildren(children []oid.ID) {
v2Children := make([]refs.ObjectID, len(children))
for i := range children {
children[i].WriteToV2(&v2Children[i])
}
(*object.SplitHeader)(sh).SetChildren(v2Children)
}
func (sh *SplitHeader) SplitID() *SplitID {
return NewSplitIDFromV2((*object.SplitHeader)(sh).GetSplitID())
}
func (sh *SplitHeader) SetSplitID(v *SplitID) {
(*object.SplitHeader)(sh).SetSplitID(v.ToV2())
}