MCPcopy
hub / github.com/grpc/grpc-go / addrToProto

Function addrToProto

channelz/internal/protoconv/socket.go:56–77  ·  view source on GitHub ↗
(a net.Addr)

Source from the content-addressed store, hash-verified

54}
55
56func addrToProto(a net.Addr) *channelzpb.Address {
57 if a == nil {
58 return nil
59 }
60 switch a.Network() {
61 case "udp":
62 // TODO: Address_OtherAddress{}. Need proto def for Value.
63 case "ip":
64 // Note zone info is discarded through the conversion.
65 return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.IPAddr).IP}}}
66 case "ip+net":
67 // Note mask info is discarded through the conversion.
68 return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.IPNet).IP}}}
69 case "tcp":
70 // Note zone info is discarded through the conversion.
71 return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.TCPAddr).IP, Port: int32(a.(*net.TCPAddr).Port)}}}
72 case "unix", "unixgram", "unixpacket":
73 return &channelzpb.Address{Address: &channelzpb.Address_UdsAddress_{UdsAddress: &channelzpb.Address_UdsAddress{Filename: a.String()}}}
74 default:
75 }
76 return &channelzpb.Address{}
77}
78
79func socketToProto(skt *channelz.Socket) *channelzpb.Socket {
80 s := &channelzpb.Socket{}

Callers 1

socketToProtoFunction · 0.70

Calls 2

StringMethod · 0.65
NetworkMethod · 0.45

Tested by

no test coverage detected