forked from TrueCloudLab/frostfs-sdk-go
121 lines
2.2 KiB
Go
121 lines
2.2 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
|
|
index uint32
|
|
total uint32
|
|
header []byte
|
|
headerLength uint32
|
|
}
|
|
|
|
// NewECHeader constructs new erasure coding header.
|
|
func NewECHeader(parent oid.ID, index, total uint32, header []byte, headerLength uint32) *ECHeader {
|
|
return &ECHeader{
|
|
parent: parent,
|
|
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.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.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) 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
|
|
}
|