From 8ebca8eff345c204bd8053aa6f7afd90a3e9c83d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 17 Aug 2020 12:12:59 +0300 Subject: [PATCH] v2/storagegroup: Implement gRPC converters Signed-off-by: Leonard Lyubich --- v2/storagegroup/convert.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 v2/storagegroup/convert.go diff --git a/v2/storagegroup/convert.go b/v2/storagegroup/convert.go new file mode 100644 index 0000000..4e45e34 --- /dev/null +++ b/v2/storagegroup/convert.go @@ -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 +}