v2/storagegroup: Implement gRPC converters
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4b7f532e52
commit
8ebca8eff3
1 changed files with 53 additions and 0 deletions
53
v2/storagegroup/convert.go
Normal file
53
v2/storagegroup/convert.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
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"
|
||||
)
|
||||
|
||||
func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
m := new(sg.StorageGroup)
|
||||
|
||||
m.SetValidationDataSize(s.GetValidationDataSize())
|
||||
m.SetValidationHash(s.GetValidationHash())
|
||||
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
|
||||
}
|
||||
|
||||
func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
s := new(StorageGroup)
|
||||
|
||||
s.SetValidationDataSize(m.GetValidationDataSize())
|
||||
s.SetValidationHash(m.GetValidationHash())
|
||||
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
|
||||
}
|
Loading…
Reference in a new issue