2020-12-10 08:30:14 +00:00
|
|
|
package tombstone
|
|
|
|
|
|
|
|
import (
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
tombstone "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
2020-12-10 08:30:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
expFNum = 1
|
|
|
|
splitIDFNum = 2
|
|
|
|
membersFNum = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
// StableMarshal marshals unified tombstone message in a protobuf
|
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (s *Tombstone) StableMarshal(buf []byte) []byte {
|
2020-12-10 08:30:14 +00:00
|
|
|
if s == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-12-10 08:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, s.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-12-10 08:30:14 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp)
|
|
|
|
offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
|
2020-12-10 08:30:14 +00:00
|
|
|
|
|
|
|
for i := range s.members {
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])
|
2020-12-10 08:30:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-12-10 08:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StableSize returns size of tombstone message marshalled by StableMarshal function.
|
|
|
|
func (s *Tombstone) StableSize() (size int) {
|
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size += proto.UInt64Size(expFNum, s.exp)
|
|
|
|
size += proto.BytesSize(splitIDFNum, s.splitID)
|
|
|
|
for i := range s.members {
|
2022-03-01 12:50:09 +00:00
|
|
|
size += proto.NestedStructureSize(membersFNum, &s.members[i])
|
2020-12-10 08:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal unmarshal tombstone message from its binary representation.
|
|
|
|
func (s *Tombstone) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(s, data, new(tombstone.Tombstone))
|
2020-12-10 08:30:14 +00:00
|
|
|
}
|