2020-08-17 11:48:08 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-03-12 12:57:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/message"
|
2020-08-17 11:48:08 +00:00
|
|
|
netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
2020-10-08 11:22:28 +00:00
|
|
|
"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"
|
2020-08-17 11:48:08 +00:00
|
|
|
)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (f *Filter) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.Filter
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if f != nil {
|
|
|
|
m = new(netmap.Filter)
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetKey(f.key)
|
|
|
|
m.SetValue(f.value)
|
|
|
|
m.SetName(f.name)
|
|
|
|
m.SetOp(OperationToGRPCMessage(f.op))
|
|
|
|
m.SetFilters(FiltersToGRPC(f.filters))
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (f *Filter) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.Filter)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
f.filters, err = FiltersFromGRPC(v.GetFilters())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
f.key = v.GetKey()
|
|
|
|
f.value = v.GetValue()
|
|
|
|
f.name = v.GetName()
|
|
|
|
f.op = OperationFromGRPCMessage(v.GetOp())
|
|
|
|
|
|
|
|
return nil
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func FiltersToGRPC(fs []*Filter) (res []*netmap.Filter) {
|
|
|
|
if fs != nil {
|
|
|
|
res = make([]*netmap.Filter, 0, len(fs))
|
|
|
|
|
|
|
|
for i := range fs {
|
|
|
|
res = append(res, fs[i].ToGRPCMessage().(*netmap.Filter))
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func FiltersFromGRPC(fs []*netmap.Filter) (res []*Filter, err error) {
|
|
|
|
if fs != nil {
|
|
|
|
res = make([]*Filter, 0, len(fs))
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range fs {
|
|
|
|
var f *Filter
|
|
|
|
|
|
|
|
if fs[i] != nil {
|
|
|
|
f = new(Filter)
|
|
|
|
|
|
|
|
err = f.FromGRPCMessage(fs[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Selector) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.Selector
|
|
|
|
|
|
|
|
if s != nil {
|
|
|
|
m = new(netmap.Selector)
|
|
|
|
|
|
|
|
m.SetName(s.name)
|
|
|
|
m.SetAttribute(s.attribute)
|
|
|
|
m.SetFilter(s.filter)
|
|
|
|
m.SetCount(s.count)
|
|
|
|
m.SetClause(ClauseToGRPCMessage(s.clause))
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (s *Selector) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.Selector)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
s.name = v.GetName()
|
|
|
|
s.attribute = v.GetAttribute()
|
|
|
|
s.filter = v.GetFilter()
|
|
|
|
s.count = v.GetCount()
|
|
|
|
s.clause = ClauseFromGRPCMessage(v.GetClause())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func SelectorsToGRPC(ss []*Selector) (res []*netmap.Selector) {
|
|
|
|
if ss != nil {
|
|
|
|
res = make([]*netmap.Selector, 0, len(ss))
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range ss {
|
|
|
|
res = append(res, ss[i].ToGRPCMessage().(*netmap.Selector))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func SelectorsFromGRPC(ss []*netmap.Selector) (res []*Selector, err error) {
|
|
|
|
if ss != nil {
|
|
|
|
res = make([]*Selector, 0, len(ss))
|
|
|
|
|
|
|
|
for i := range ss {
|
|
|
|
var s *Selector
|
|
|
|
|
|
|
|
if ss[i] != nil {
|
|
|
|
s = new(Selector)
|
|
|
|
|
|
|
|
err = s.FromGRPCMessage(ss[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, s)
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Replica) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.Replica
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if r != nil {
|
|
|
|
m = new(netmap.Replica)
|
|
|
|
|
|
|
|
m.SetSelector(r.selector)
|
|
|
|
m.SetCount(r.count)
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *Replica) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.Replica)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.selector = v.GetSelector()
|
|
|
|
r.count = v.GetCount()
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ReplicasToGRPC(rs []*Replica) (res []*netmap.Replica) {
|
|
|
|
if rs != nil {
|
|
|
|
res = make([]*netmap.Replica, 0, len(rs))
|
2020-08-17 11:48:08 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range rs {
|
|
|
|
res = append(res, rs[i].ToGRPCMessage().(*netmap.Replica))
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReplicasFromGRPC(rs []*netmap.Replica) (res []*Replica, err error) {
|
|
|
|
if rs != nil {
|
|
|
|
res = make([]*Replica, 0, len(rs))
|
|
|
|
|
|
|
|
for i := range rs {
|
|
|
|
var r *Replica
|
|
|
|
|
|
|
|
if rs[i] != nil {
|
|
|
|
r = new(Replica)
|
|
|
|
|
|
|
|
err = r.FromGRPCMessage(rs[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
res = append(res, r)
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PlacementPolicy) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.PlacementPolicy
|
|
|
|
|
|
|
|
if p != nil {
|
|
|
|
m = new(netmap.PlacementPolicy)
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetFilters(FiltersToGRPC(p.filters))
|
|
|
|
m.SetSelectors(SelectorsToGRPC(p.selectors))
|
|
|
|
m.SetReplicas(ReplicasToGRPC(p.replicas))
|
|
|
|
m.SetContainerBackupFactor(p.backupFactor)
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
|
|
|
return m
|
2020-08-17 11:48:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (p *PlacementPolicy) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.PlacementPolicy)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 11:48:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
p.filters, err = FiltersFromGRPC(v.GetFilters())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
p.selectors, err = SelectorsFromGRPC(v.GetSelectors())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
p.replicas, err = ReplicasFromGRPC(v.GetReplicas())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
p.backupFactor = v.GetContainerBackupFactor()
|
2020-09-04 10:05:56 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-09-04 10:05:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 10:19:22 +00:00
|
|
|
func ClauseToGRPCMessage(n Clause) netmap.Clause {
|
|
|
|
return netmap.Clause(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ClauseFromGRPCMessage(n netmap.Clause) Clause {
|
|
|
|
return Clause(n)
|
|
|
|
}
|
|
|
|
|
2020-09-04 10:05:56 +00:00
|
|
|
func OperationToGRPCMessage(n Operation) netmap.Operation {
|
|
|
|
return netmap.Operation(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OperationFromGRPCMessage(n netmap.Operation) Operation {
|
|
|
|
return Operation(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NodeStateToGRPCMessage(n NodeState) netmap.NodeInfo_State {
|
|
|
|
return netmap.NodeInfo_State(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NodeStateFromRPCMessage(n netmap.NodeInfo_State) NodeState {
|
|
|
|
return NodeState(n)
|
2020-08-17 11:48:08 +00:00
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (a *Attribute) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NodeInfo_Attribute
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if a != nil {
|
|
|
|
m = new(netmap.NodeInfo_Attribute)
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetKey(a.key)
|
|
|
|
m.SetValue(a.value)
|
|
|
|
m.SetParents(a.parents)
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NodeInfo_Attribute)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
a.key = v.GetKey()
|
|
|
|
a.value = v.GetValue()
|
|
|
|
a.parents = v.GetParents()
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func AttributesToGRPC(as []*Attribute) (res []*netmap.NodeInfo_Attribute) {
|
|
|
|
if as != nil {
|
|
|
|
res = make([]*netmap.NodeInfo_Attribute, 0, len(as))
|
|
|
|
|
|
|
|
for i := range as {
|
|
|
|
res = append(res, as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute))
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func AttributesFromGRPC(as []*netmap.NodeInfo_Attribute) (res []*Attribute, err error) {
|
|
|
|
if as != nil {
|
|
|
|
res = make([]*Attribute, 0, len(as))
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range as {
|
|
|
|
var a *Attribute
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if as[i] != nil {
|
|
|
|
a = new(Attribute)
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = a.FromGRPCMessage(as[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
res = append(res, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (ni *NodeInfo) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NodeInfo
|
|
|
|
|
|
|
|
if ni != nil {
|
|
|
|
m = new(netmap.NodeInfo)
|
|
|
|
|
|
|
|
m.SetPublicKey(ni.publicKey)
|
|
|
|
m.SetAddress(ni.address)
|
|
|
|
m.SetState(NodeStateToGRPCMessage(ni.state))
|
|
|
|
m.SetAttributes(AttributesToGRPC(ni.attributes))
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (ni *NodeInfo) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NodeInfo)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
ni.attributes, err = AttributesFromGRPC(v.GetAttributes())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
ni.publicKey = v.GetPublicKey()
|
|
|
|
ni.address = v.GetAddress()
|
|
|
|
ni.state = NodeStateFromRPCMessage(v.GetState())
|
2020-09-01 07:46:20 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-09-01 07:46:20 +00:00
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoRequestBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.LocalNodeInfoRequest_Body
|
|
|
|
|
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.LocalNodeInfoRequest_Body)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoRequestBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.LocalNodeInfoRequest_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoRequest) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.LocalNodeInfoRequest
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.LocalNodeInfoRequest)
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoRequest_Body))
|
|
|
|
l.RequestHeaders.ToMessage(m)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoRequest) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.LocalNodeInfoRequest)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
l.body = nil
|
|
|
|
} else {
|
|
|
|
if l.body == nil {
|
|
|
|
l.body = new(LocalNodeInfoRequestBody)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = l.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return l.RequestHeaders.FromMessage(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LocalNodeInfoResponseBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.LocalNodeInfoResponse_Body
|
|
|
|
|
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.LocalNodeInfoResponse_Body)
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVersion(l.version.ToGRPCMessage().(*refsGRPC.Version))
|
|
|
|
m.SetNodeInfo(l.nodeInfo.ToGRPCMessage().(*netmap.NodeInfo))
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoResponseBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.LocalNodeInfoResponse_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
version := v.GetVersion()
|
|
|
|
if version == nil {
|
|
|
|
l.version = nil
|
|
|
|
} else {
|
|
|
|
if l.version == nil {
|
|
|
|
l.version = new(refs.Version)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = l.version.FromGRPCMessage(version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeInfo := v.GetNodeInfo()
|
|
|
|
if nodeInfo == nil {
|
|
|
|
l.nodeInfo = nil
|
|
|
|
} else {
|
|
|
|
if l.nodeInfo == nil {
|
|
|
|
l.nodeInfo = new(NodeInfo)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = l.nodeInfo.FromGRPCMessage(nodeInfo)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LocalNodeInfoResponse) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.LocalNodeInfoResponse
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.LocalNodeInfoResponse)
|
|
|
|
|
|
|
|
m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoResponse_Body))
|
|
|
|
l.ResponseHeaders.ToMessage(m)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *LocalNodeInfoResponse) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.LocalNodeInfoResponse)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
l.body = nil
|
|
|
|
} else {
|
|
|
|
if l.body == nil {
|
|
|
|
l.body = new(LocalNodeInfoResponseBody)
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = l.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 11:22:28 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return l.ResponseHeaders.FromMessage(v)
|
2020-10-08 11:22:28 +00:00
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (i *NetworkInfo) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NetworkInfo
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if i != nil {
|
|
|
|
m = new(netmap.NetworkInfo)
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMagicNumber(i.magicNum)
|
|
|
|
m.SetCurrentEpoch(i.curEpoch)
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (i *NetworkInfo) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NetworkInfo)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
i.magicNum = v.GetMagicNumber()
|
|
|
|
i.curEpoch = v.GetCurrentEpoch()
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoRequestBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NetworkInfoRequest_Body
|
|
|
|
|
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.NetworkInfoRequest_Body)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoRequestBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NetworkInfoRequest_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoRequest) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NetworkInfoRequest
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.NetworkInfoRequest)
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoRequest_Body))
|
|
|
|
l.RequestHeaders.ToMessage(m)
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoRequest) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NetworkInfoRequest)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
l.body = nil
|
|
|
|
} else {
|
|
|
|
if l.body == nil {
|
|
|
|
l.body = new(NetworkInfoRequestBody)
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = l.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return l.RequestHeaders.FromMessage(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *NetworkInfoResponseBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NetworkInfoResponse_Body
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if i != nil {
|
|
|
|
m = new(netmap.NetworkInfoResponse_Body)
|
|
|
|
|
|
|
|
m.SetNetworkInfo(i.netInfo.ToGRPCMessage().(*netmap.NetworkInfo))
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (i *NetworkInfoResponseBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NetworkInfoResponse_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
netInfo := v.GetNetworkInfo()
|
|
|
|
if netInfo == nil {
|
|
|
|
i.netInfo = nil
|
|
|
|
} else {
|
|
|
|
if i.netInfo == nil {
|
|
|
|
i.netInfo = new(NetworkInfo)
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = i.netInfo.FromGRPCMessage(netInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoResponse) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *netmap.NetworkInfoResponse
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(netmap.NetworkInfoResponse)
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoResponse_Body))
|
|
|
|
l.ResponseHeaders.ToMessage(m)
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *NetworkInfoResponse) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*netmap.NetworkInfoResponse)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
l.body = nil
|
|
|
|
} else {
|
|
|
|
if l.body == nil {
|
|
|
|
l.body = new(NetworkInfoResponseBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = l.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 17:17:44 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return l.ResponseHeaders.FromMessage(v)
|
2021-02-17 17:17:44 +00:00
|
|
|
}
|