2020-08-17 09:12:59 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
sg "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/storagegroup/grpc"
|
2020-08-17 09:12:59 +00:00
|
|
|
)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (s *StorageGroup) ToGRPCMessage() grpc.Message {
|
2020-08-17 09:12:59 +00:00
|
|
|
m := new(sg.StorageGroup)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if s != nil {
|
|
|
|
m = new(sg.StorageGroup)
|
2020-08-17 09:12:59 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMembers(refs.ObjectIDListToGRPCMessage(s.members))
|
2022-09-17 06:39:11 +00:00
|
|
|
//nolint:staticcheck
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetExpirationEpoch(s.exp)
|
|
|
|
m.SetValidationDataSize(s.size)
|
|
|
|
m.SetValidationHash(s.hash.ToGRPCMessage().(*refsGRPC.Checksum))
|
|
|
|
}
|
2020-08-17 09:12:59 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (s *StorageGroup) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*sg.StorageGroup)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:12:59 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
hash := v.GetValidationHash()
|
|
|
|
if hash == nil {
|
|
|
|
s.hash = nil
|
|
|
|
} else {
|
|
|
|
if s.hash == nil {
|
|
|
|
s.hash = new(refs.Checksum)
|
|
|
|
}
|
2020-08-17 09:12:59 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = s.hash.FromGRPCMessage(hash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.members, err = refs.ObjectIDListFromGRPCMessage(v.GetMembers())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-17 09:12:59 +00:00
|
|
|
|
2022-09-17 06:39:11 +00:00
|
|
|
//nolint:staticcheck
|
2021-03-12 12:57:23 +00:00
|
|
|
s.exp = v.GetExpirationEpoch()
|
|
|
|
s.size = v.GetValidationDataSize()
|
2020-08-17 09:12:59 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-17 09:12:59 +00:00
|
|
|
}
|