2020-08-17 09:12:59 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
2022-12-09 11:16:24 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
refsGRPC "github.com/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
sg "github.com/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
|
|
|
}
|