git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/object/tombstone.go (about) 1 package object 2 3 import ( 4 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" 5 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" 6 oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" 7 ) 8 9 // Tombstone represents v2-compatible tombstone structure. 10 type Tombstone tombstone.Tombstone 11 12 // NewTombstoneFromV2 wraps v2 Tombstone message to Tombstone. 13 // 14 // Nil tombstone.Tombstone converts to nil. 15 func NewTombstoneFromV2(tV2 *tombstone.Tombstone) *Tombstone { 16 return (*Tombstone)(tV2) 17 } 18 19 // NewTombstone creates and initializes blank Tombstone. 20 // 21 // Defaults: 22 // - exp: 0; 23 // - splitID: nil; 24 // - members: nil. 25 func NewTombstone() *Tombstone { 26 return NewTombstoneFromV2(new(tombstone.Tombstone)) 27 } 28 29 // ToV2 converts Tombstone to v2 Tombstone message. 30 // 31 // Nil Tombstone converts to nil. 32 func (t *Tombstone) ToV2() *tombstone.Tombstone { 33 return (*tombstone.Tombstone)(t) 34 } 35 36 // ExpirationEpoch returns the last FrostFS epoch 37 // number of the tombstone lifetime. 38 // 39 // See also SetExpirationEpoch. 40 func (t *Tombstone) ExpirationEpoch() uint64 { 41 return (*tombstone.Tombstone)(t).GetExpirationEpoch() 42 } 43 44 // SetExpirationEpoch sets the last FrostFS epoch 45 // number of the tombstone lifetime. 46 // 47 // See also ExpirationEpoch. 48 func (t *Tombstone) SetExpirationEpoch(v uint64) { 49 (*tombstone.Tombstone)(t).SetExpirationEpoch(v) 50 } 51 52 // SplitID returns identifier of object split hierarchy. 53 func (t *Tombstone) SplitID() *SplitID { 54 return NewSplitIDFromV2( 55 (*tombstone.Tombstone)(t).GetSplitID()) 56 } 57 58 // SetSplitID sets identifier of object split hierarchy. 59 func (t *Tombstone) SetSplitID(v *SplitID) { 60 (*tombstone.Tombstone)(t).SetSplitID(v.ToV2()) 61 } 62 63 // Members returns list of objects to be deleted. 64 func (t *Tombstone) Members() []oid.ID { 65 v2 := (*tombstone.Tombstone)(t) 66 msV2 := v2.GetMembers() 67 68 if msV2 == nil { 69 return nil 70 } 71 72 var ( 73 ms = make([]oid.ID, len(msV2)) 74 id oid.ID 75 ) 76 77 for i := range msV2 { 78 _ = id.ReadFromV2(msV2[i]) 79 ms[i] = id 80 } 81 82 return ms 83 } 84 85 // SetMembers sets list of objects to be deleted. 86 func (t *Tombstone) SetMembers(v []oid.ID) { 87 var ms []refs.ObjectID 88 89 if v != nil { 90 ms = (*tombstone.Tombstone)(t). 91 GetMembers() 92 93 if ln := len(v); cap(ms) >= ln { 94 ms = ms[:0] 95 } else { 96 ms = make([]refs.ObjectID, 0, ln) 97 } 98 99 var idV2 refs.ObjectID 100 101 for i := range v { 102 v[i].WriteToV2(&idV2) 103 ms = append(ms, idV2) 104 } 105 } 106 107 (*tombstone.Tombstone)(t).SetMembers(ms) 108 } 109 110 // Marshal marshals Tombstone into a protobuf binary form. 111 func (t *Tombstone) Marshal() ([]byte, error) { 112 return (*tombstone.Tombstone)(t).StableMarshal(nil), nil 113 } 114 115 // Unmarshal unmarshals protobuf binary representation of Tombstone. 116 func (t *Tombstone) Unmarshal(data []byte) error { 117 return (*tombstone.Tombstone)(t).Unmarshal(data) 118 } 119 120 // MarshalJSON encodes Tombstone to protobuf JSON format. 121 func (t *Tombstone) MarshalJSON() ([]byte, error) { 122 return (*tombstone.Tombstone)(t).MarshalJSON() 123 } 124 125 // UnmarshalJSON decodes Tombstone from protobuf JSON format. 126 func (t *Tombstone) UnmarshalJSON(data []byte) error { 127 return (*tombstone.Tombstone)(t).UnmarshalJSON(data) 128 }