Airat Arifullin
443098cb28
Some checks failed
DCO action / DCO (pull_request) Successful in 48s
Tests and linters / Tests (1.19) (pull_request) Failing after 59s
Tests and linters / Tests with -race (pull_request) Successful in 1m31s
Tests and linters / Tests (1.20) (pull_request) Failing after 5m52s
Tests and linters / Lint (pull_request) Successful in 7m3s
* Use protowire.AppendTag to encode a tag and append it * Use protowire.AppendVarint to append numeric data * Use protowire.AppendBytes and protowire.AppendString Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package tombstone
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
const (
|
|
expFNum = 1
|
|
splitIDFNum = 2
|
|
membersFNum = 3
|
|
)
|
|
|
|
// StableMarshal marshals unified tombstone message in a protobuf
|
|
// compatible way without field order shuffle.
|
|
func (s *Tombstone) StableMarshal(buf []byte) []byte {
|
|
if s == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, s.StableSize())
|
|
}
|
|
|
|
var offset int
|
|
|
|
buf = proto.UInt64Marshal(expFNum, buf[offset:], s.exp)
|
|
buf = proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
|
|
|
|
for i := range s.members {
|
|
buf = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])
|
|
}
|
|
|
|
return buf
|
|
}
|
|
|
|
// 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 {
|
|
size += proto.NestedStructureSize(membersFNum, &s.members[i])
|
|
}
|
|
|
|
return size
|
|
}
|
|
|
|
// Unmarshal unmarshal tombstone message from its binary representation.
|
|
func (s *Tombstone) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(s, data, new(tombstone.Tombstone))
|
|
}
|