github.com/annwntech/go-micro/v2@v2.9.5/util/proto/proto.go (about)

     1  // Package proto contains utility functions for working with protobufs
     2  package proto
     3  
     4  import (
     5  	"github.com/annwntech/go-micro/v2/router"
     6  	pbRtr "github.com/annwntech/go-micro/v2/router/service/proto"
     7  )
     8  
     9  // RouteToProto encodes route into protobuf and returns it
    10  func RouteToProto(route router.Route) *pbRtr.Route {
    11  	return &pbRtr.Route{
    12  		Service: route.Service,
    13  		Address: route.Address,
    14  		Gateway: route.Gateway,
    15  		Network: route.Network,
    16  		Router:  route.Router,
    17  		Link:    route.Link,
    18  		Metric:  int64(route.Metric),
    19  	}
    20  }
    21  
    22  // ProtoToRoute decodes protobuf route into router route and returns it
    23  func ProtoToRoute(route *pbRtr.Route) router.Route {
    24  	return router.Route{
    25  		Service: route.Service,
    26  		Address: route.Address,
    27  		Gateway: route.Gateway,
    28  		Network: route.Network,
    29  		Router:  route.Router,
    30  		Link:    route.Link,
    31  		Metric:  route.Metric,
    32  	}
    33  }