2021-11-08 10:04:45 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/tombstone"
|
2022-01-25 16:20:32 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-08 10:04:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Tombstone represents v2-compatible tombstone structure.
|
|
|
|
type Tombstone tombstone.Tombstone
|
|
|
|
|
|
|
|
// NewTombstoneFromV2 wraps v2 Tombstone message to Tombstone.
|
|
|
|
//
|
|
|
|
// Nil tombstone.Tombstone converts to nil.
|
|
|
|
func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone {
|
|
|
|
return (*Tombstone)(tV2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTombstone creates and initializes blank Tombstone.
|
|
|
|
//
|
|
|
|
// Defaults:
|
|
|
|
// - exp: 0;
|
|
|
|
// - splitID: nil;
|
|
|
|
// - members: nil.
|
|
|
|
func NewTombstone() *Tombstone {
|
|
|
|
return NewTombstoneFromV2(new(tombstone.Tombstone))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToV2 converts Tombstone to v2 Tombstone message.
|
|
|
|
//
|
|
|
|
// Nil Tombstone converts to nil.
|
|
|
|
func (t *Tombstone) ToV2() *tombstone.Tombstone {
|
|
|
|
return (*tombstone.Tombstone)(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpirationEpoch return number of tombstone expiration epoch.
|
|
|
|
func (t *Tombstone) ExpirationEpoch() uint64 {
|
|
|
|
return (*tombstone.Tombstone)(t).GetExpirationEpoch()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetExpirationEpoch sets number of tombstone expiration epoch.
|
|
|
|
func (t *Tombstone) SetExpirationEpoch(v uint64) {
|
|
|
|
(*tombstone.Tombstone)(t).SetExpirationEpoch(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SplitID returns identifier of object split hierarchy.
|
|
|
|
func (t *Tombstone) SplitID() *SplitID {
|
|
|
|
return NewSplitIDFromV2(
|
|
|
|
(*tombstone.Tombstone)(t).GetSplitID())
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSplitID sets identifier of object split hierarchy.
|
|
|
|
func (t *Tombstone) SetSplitID(v *SplitID) {
|
|
|
|
(*tombstone.Tombstone)(t).SetSplitID(v.ToV2())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Members returns list of objects to be deleted.
|
2022-03-11 09:00:54 +00:00
|
|
|
func (t *Tombstone) Members() []oid.ID {
|
2021-11-08 10:04:45 +00:00
|
|
|
msV2 := (*tombstone.Tombstone)(t).
|
|
|
|
GetMembers()
|
|
|
|
|
|
|
|
if msV2 == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-11 09:00:54 +00:00
|
|
|
ms := make([]oid.ID, len(msV2))
|
2021-11-08 10:04:45 +00:00
|
|
|
|
|
|
|
for i := range msV2 {
|
2022-03-11 09:00:54 +00:00
|
|
|
ms[i] = *oid.NewIDFromV2(&msV2[i])
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ms
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMembers sets list of objects to be deleted.
|
2022-03-11 09:00:54 +00:00
|
|
|
func (t *Tombstone) SetMembers(v []oid.ID) {
|
|
|
|
var ms []refs.ObjectID
|
2021-11-08 10:04:45 +00:00
|
|
|
|
|
|
|
if v != nil {
|
|
|
|
ms = (*tombstone.Tombstone)(t).
|
|
|
|
GetMembers()
|
|
|
|
|
|
|
|
if ln := len(v); cap(ms) >= ln {
|
|
|
|
ms = ms[:0]
|
|
|
|
} else {
|
2022-03-11 09:00:54 +00:00
|
|
|
ms = make([]refs.ObjectID, 0, ln)
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range v {
|
2022-03-11 09:00:54 +00:00
|
|
|
ms = append(ms, *v[i].ToV2())
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*tombstone.Tombstone)(t).SetMembers(ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal marshals Tombstone into a protobuf binary form.
|
|
|
|
func (t *Tombstone) Marshal() ([]byte, error) {
|
2022-05-05 08:00:13 +00:00
|
|
|
return (*tombstone.Tombstone)(t).StableMarshal(nil), nil
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal unmarshals protobuf binary representation of Tombstone.
|
|
|
|
func (t *Tombstone) Unmarshal(data []byte) error {
|
|
|
|
return (*tombstone.Tombstone)(t).Unmarshal(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON encodes Tombstone to protobuf JSON format.
|
|
|
|
func (t *Tombstone) MarshalJSON() ([]byte, error) {
|
|
|
|
return (*tombstone.Tombstone)(t).MarshalJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON decodes Tombstone from protobuf JSON format.
|
|
|
|
func (t *Tombstone) UnmarshalJSON(data []byte) error {
|
|
|
|
return (*tombstone.Tombstone)(t).UnmarshalJSON(data)
|
|
|
|
}
|