2020-08-17 09:12:59 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2021-03-12 12:57:23 +00:00
|
|
|
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
2021-11-16 17:30:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/message"
|
2020-08-17 09:12:59 +00:00
|
|
|
sg "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc"
|
|
|
|
)
|
|
|
|
|
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))
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|