2020-08-17 09:12:59 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
|
|
|
sg "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc"
|
|
|
|
)
|
|
|
|
|
2020-08-17 12:19:36 +00:00
|
|
|
// StorageGroupToGRPCMessage converts unified proto structure into grpc structure.
|
2020-08-17 09:12:59 +00:00
|
|
|
func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
|
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
m := new(sg.StorageGroup)
|
|
|
|
|
|
|
|
m.SetValidationDataSize(s.GetValidationDataSize())
|
2020-08-20 08:04:16 +00:00
|
|
|
m.SetValidationHash(
|
|
|
|
refs.ChecksumToGRPCMessage(s.GetValidationHash()),
|
|
|
|
)
|
2020-08-17 09:12:59 +00:00
|
|
|
m.SetExpirationEpoch(s.GetExpirationEpoch())
|
|
|
|
|
|
|
|
members := s.GetMembers()
|
|
|
|
memberMsg := make([]*refsGRPC.ObjectID, 0, len(members))
|
|
|
|
|
|
|
|
for i := range members {
|
|
|
|
memberMsg = append(memberMsg, refs.ObjectIDToGRPCMessage(members[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
m.SetMembers(memberMsg)
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-08-17 12:19:36 +00:00
|
|
|
// StorageGroupFromGRPCMessage converts grpc structure into unified proto structure.
|
2020-08-17 09:12:59 +00:00
|
|
|
func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup {
|
|
|
|
if m == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
s := new(StorageGroup)
|
|
|
|
|
|
|
|
s.SetValidationDataSize(m.GetValidationDataSize())
|
2020-08-20 08:04:16 +00:00
|
|
|
s.SetValidationHash(
|
|
|
|
refs.ChecksumFromGRPCMessage(m.GetValidationHash()),
|
|
|
|
)
|
2020-08-17 09:12:59 +00:00
|
|
|
s.SetExpirationEpoch(m.GetExpirationEpoch())
|
|
|
|
|
|
|
|
memberMsg := m.GetMembers()
|
|
|
|
members := make([]*refs.ObjectID, 0, len(memberMsg))
|
|
|
|
|
|
|
|
for i := range memberMsg {
|
|
|
|
members = append(members, refs.ObjectIDFromGRPCMessage(memberMsg[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
s.SetMembers(members)
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|