1031f3122e
Implement `message.Message` interface on all structures and use new methods for conversion instead of functions. make `Unmarshal` and JSON methods to use encoding functions from `message` library. Remove all per-service clients and implement `rpc` library of the functions which execute NeoFS API RPC through new RPC client. Remove no longer used gRPC per-service clients. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package storagegroup
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/message"
|
|
"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 (s *StorageGroup) ToGRPCMessage() grpc.Message {
|
|
m := new(sg.StorageGroup)
|
|
|
|
if s != nil {
|
|
m = new(sg.StorageGroup)
|
|
|
|
m.SetMembers(refs.ObjectIDListToGRPCMessage(s.members))
|
|
m.SetExpirationEpoch(s.exp)
|
|
m.SetValidationDataSize(s.size)
|
|
m.SetValidationHash(s.hash.ToGRPCMessage().(*refsGRPC.Checksum))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func (s *StorageGroup) FromGRPCMessage(m grpc.Message) error {
|
|
v, ok := m.(*sg.StorageGroup)
|
|
if !ok {
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
}
|
|
|
|
var err error
|
|
|
|
hash := v.GetValidationHash()
|
|
if hash == nil {
|
|
s.hash = nil
|
|
} else {
|
|
if s.hash == nil {
|
|
s.hash = new(refs.Checksum)
|
|
}
|
|
|
|
err = s.hash.FromGRPCMessage(hash)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
s.members, err = refs.ObjectIDListFromGRPCMessage(v.GetMembers())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
s.exp = v.GetExpirationEpoch()
|
|
s.size = v.GetValidationDataSize()
|
|
|
|
return nil
|
|
}
|