2022-02-15 05:41:03 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2024-10-07 14:20:25 +00:00
|
|
|
v2object "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2023-03-07 11:20:03 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-02-15 05:41:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lock represents record with locked objects. It is compatible with
|
2022-12-29 10:46:18 +00:00
|
|
|
// FrostFS API V2 protocol.
|
2022-03-05 13:54:28 +00:00
|
|
|
//
|
|
|
|
// Lock instance can be written to the Object, see WriteLock/ReadLock.
|
2022-02-15 05:41:03 +00:00
|
|
|
type Lock v2object.Lock
|
|
|
|
|
2022-03-05 13:54:28 +00:00
|
|
|
// WriteLock writes Lock to the Object, and sets its type to TypeLock.
|
|
|
|
// The object must not be nil.
|
|
|
|
//
|
|
|
|
// See also ReadLock.
|
|
|
|
func WriteLock(obj *Object, l Lock) {
|
|
|
|
obj.SetType(TypeLock)
|
|
|
|
obj.SetPayload(l.Marshal())
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadLock reads Lock from the Object. The lock must not be nil.
|
|
|
|
// Returns an error describing incorrect format. Makes sense only
|
|
|
|
// if object has TypeLock type.
|
|
|
|
//
|
|
|
|
// See also WriteLock.
|
|
|
|
func ReadLock(l *Lock, obj Object) error {
|
|
|
|
return l.Unmarshal(obj.Payload())
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
// NumberOfMembers returns number of members in lock list.
|
|
|
|
func (x Lock) NumberOfMembers() int {
|
|
|
|
return (*v2object.Lock)(&x).NumberOfMembers()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadMembers reads list of locked members.
|
|
|
|
//
|
|
|
|
// Buffer length must not be less than NumberOfMembers.
|
|
|
|
func (x Lock) ReadMembers(buf []oid.ID) {
|
|
|
|
var i int
|
|
|
|
|
2022-04-11 16:25:14 +00:00
|
|
|
(*v2object.Lock)(&x).IterateMembers(func(idV2 refs.ObjectID) {
|
|
|
|
_ = buf[i].ReadFromV2(idV2)
|
2022-02-15 05:41:03 +00:00
|
|
|
i++
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteMembers writes list of locked members.
|
|
|
|
func (x *Lock) WriteMembers(ids []oid.ID) {
|
|
|
|
var members []refs.ObjectID
|
|
|
|
|
|
|
|
if ids != nil {
|
|
|
|
members = make([]refs.ObjectID, len(ids))
|
|
|
|
|
|
|
|
for i := range ids {
|
2022-04-11 16:25:14 +00:00
|
|
|
ids[i].WriteToV2(&members[i])
|
2022-02-15 05:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*v2object.Lock)(x).SetMembers(members)
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// Marshal encodes the Lock into a FrostFS protocol binary format.
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x Lock) Marshal() []byte {
|
2022-05-30 19:05:35 +00:00
|
|
|
return (*v2object.Lock)(&x).StableMarshal(nil)
|
2022-02-15 05:41:03 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// Unmarshal decodes the Lock from its FrostFS protocol binary representation.
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x *Lock) Unmarshal(data []byte) error {
|
|
|
|
return (*v2object.Lock)(x).Unmarshal(data)
|
|
|
|
}
|