Airat Arifullin
3de256d05e
* Introduce `parentSplitID`, `parentSplitParentID` fields for `ECHeader`; * Fix ECHeader's constructor; * Fix `Split` and `Reconstruct`; * Add unit-tests. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
156 lines
3.3 KiB
Go
156 lines
3.3 KiB
Go
package object
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
)
|
|
|
|
// ECHeader represents erasure coding header.
|
|
type ECHeader struct {
|
|
parent oid.ID
|
|
parentSplitID *SplitID
|
|
parentSplitParentID *oid.ID
|
|
index uint32
|
|
total uint32
|
|
header []byte
|
|
headerLength uint32
|
|
}
|
|
|
|
// NewECHeader constructs new erasure coding header.
|
|
func NewECHeader(parent oid.ID, parentSplitID *SplitID, parentSplitParentID *oid.ID, index, total uint32, header []byte, headerLength uint32) *ECHeader {
|
|
return &ECHeader{
|
|
parent: parent,
|
|
parentSplitID: parentSplitID,
|
|
parentSplitParentID: parentSplitParentID,
|
|
index: index,
|
|
total: total,
|
|
header: header,
|
|
headerLength: headerLength,
|
|
}
|
|
}
|
|
|
|
// WriteToV2 converts SDK structure to v2-api one.
|
|
func (e *ECHeader) WriteToV2(h *object.ECHeader) {
|
|
var parent refs.ObjectID
|
|
e.parent.WriteToV2(&parent)
|
|
h.ParentSplitID = e.parentSplitID.ToV2()
|
|
|
|
if e.parentSplitParentID != nil {
|
|
parentSplitParentID := new(refs.ObjectID)
|
|
e.parentSplitParentID.WriteToV2(parentSplitParentID)
|
|
h.ParentSplitParentID = parentSplitParentID
|
|
}
|
|
|
|
h.Parent = &parent
|
|
h.Index = e.index
|
|
h.Total = e.total
|
|
h.Header = e.header
|
|
h.HeaderLength = e.headerLength
|
|
}
|
|
|
|
// ReadFromV2 converts v2-api structure to SDK one.
|
|
func (e *ECHeader) ReadFromV2(h *object.ECHeader) error {
|
|
if h == nil {
|
|
return nil
|
|
}
|
|
if h.Parent == nil {
|
|
return errors.New("empty parent")
|
|
}
|
|
|
|
_ = e.parent.ReadFromV2(*h.Parent)
|
|
e.parentSplitID = NewSplitIDFromV2(h.ParentSplitID)
|
|
if h.ParentSplitParentID != nil {
|
|
if e.parentSplitParentID == nil {
|
|
e.parentSplitParentID = new(oid.ID)
|
|
}
|
|
_ = e.parentSplitParentID.ReadFromV2(*h.ParentSplitParentID)
|
|
}
|
|
e.index = h.Index
|
|
e.total = h.Total
|
|
e.header = h.Header
|
|
e.headerLength = h.HeaderLength
|
|
return nil
|
|
}
|
|
|
|
func (o *Object) ECHeader() *ECHeader {
|
|
ec := (*object.Object)(o).GetHeader().GetEC()
|
|
if ec == nil {
|
|
return nil
|
|
}
|
|
|
|
h := new(ECHeader)
|
|
_ = h.ReadFromV2(ec)
|
|
return h
|
|
}
|
|
|
|
func (o *Object) SetECHeader(ec *ECHeader) {
|
|
o.setHeaderField(func(h *object.Header) {
|
|
if ec == nil {
|
|
h.SetEC(nil)
|
|
return
|
|
}
|
|
|
|
v2 := new(object.ECHeader)
|
|
ec.WriteToV2(v2)
|
|
h.SetEC(v2)
|
|
})
|
|
}
|
|
|
|
func (e *ECHeader) Parent() oid.ID {
|
|
return e.parent
|
|
}
|
|
|
|
func (e *ECHeader) SetParent(id oid.ID) {
|
|
e.parent = id
|
|
}
|
|
|
|
func (e *ECHeader) ParentSplitID() *SplitID {
|
|
return e.parentSplitID
|
|
}
|
|
|
|
func (e *ECHeader) SetParentSplitID(parentSplitID *SplitID) {
|
|
e.parentSplitID = parentSplitID
|
|
}
|
|
|
|
func (e *ECHeader) ParentSplitParentID() *oid.ID {
|
|
return e.parentSplitParentID
|
|
}
|
|
|
|
func (e *ECHeader) SetParentSplitParentID(parentSplitParentID *oid.ID) {
|
|
e.parentSplitParentID = parentSplitParentID
|
|
}
|
|
|
|
func (e *ECHeader) Index() uint32 {
|
|
return e.index
|
|
}
|
|
|
|
func (e *ECHeader) SetIndex(i uint32) {
|
|
e.index = i
|
|
}
|
|
|
|
func (e *ECHeader) Total() uint32 {
|
|
return e.total
|
|
}
|
|
|
|
func (e *ECHeader) SetTotal(i uint32) {
|
|
e.total = i
|
|
}
|
|
|
|
func (e *ECHeader) Header() []byte {
|
|
return e.header
|
|
}
|
|
|
|
func (e *ECHeader) SetHeader(header []byte) {
|
|
e.header = header
|
|
}
|
|
|
|
func (e *ECHeader) HeaderLength() uint32 {
|
|
return e.headerLength
|
|
}
|
|
|
|
func (e *ECHeader) SetHeaderLength(l uint32) {
|
|
e.headerLength = l
|
|
}
|