// Proto returns the protocol of a Port
541519
func (p Port) Proto() string {
	proto, _ := SplitProtoPort(string(p))
	return proto
}
1015219
func (sp *SerializerProto) Marshal(message proto.Message) ([]byte, error) {
	return proto.Marshal(message)
}
827409
func Protocol(url string) string {
	if index := strings.Index(url, "://"); index > -1 {
		return url[:index]
	}
	return ""
}
1223407
func protocolToString(proto Protocol) string {
	switch proto {
	case syscall.IPPROTO_TCP:
		return "TCP"
	case syscall.IPPROTO_UDP:
		return "UDP"
	case syscall.IPPROTO_SCTP:
		return "SCTP"
	}
	return ""
}
296620
func portName(port int, protocol corev1.Protocol) string {
	if protocol == "" {
		protocol = corev1.ProtocolTCP
	}
	return strings.ToLower(fmt.Sprintf("%d-%s", port, protocol))
}
15758
func (s *Stream) Protocol() protocol.ID {
	// Ignore type error. It means that the protocol is unset.
	p, _ := s.protocol.Load().(protocol.ID)
	return p
}
845669
func (container *Container) Expose(ports ...int) *Container {
	for _, port := range ports {
		container.ExposePort(PortMapping{
			ContainerPort: port,
			HostPort:      0,
			ServicePort:   0,
			Protocol:      "tcp"})
	}
	return container
}
134081
func Listen(proto, addr string) (l net.Listener, err error) {
	return NewReusablePortListener(proto, addr)
}
1315525
func NewPortMapping(proto, from, to string) (*PortMapping, error) {
	if proto == "" {
		proto = "tcp"
	}
	if proto != "tcp" && proto != "udp" {
		return nil, fmt.Errorf("unsupported protocol %s", proto)
	}
	f, err := NewPortRange(from)
	if err != nil {
		return nil, err
	}
	t, err := NewPortRange(to)
	if err != nil {
		return nil, err
	}
	return &PortMapping{
		Protocol:  proto,
		ToPorts:   t,
		FromPorts: f,
	}, nil
}
249974
func (p PortRange) String() string {
	proto := strings.ToLower(p.Protocol)
	if proto == "icmp" {
		return fmt.Sprintf("%s (%q)", proto, p.UnitName)
	}
	return fmt.Sprintf("%d-%d/%s (%q)", p.FromPort, p.ToPort, proto, p.UnitName)
}
878556
func (e *Ref) Proto() *api.Ref {
	return &api.Ref{
		Name:       e.Name,
		Package:    e.Package.StringID(),
		Instance:   common.InstanceIDToObjectRef(e.InstanceID),
		ModifiedBy: e.ModifiedBy,
		ModifiedTs: google.NewTimestamp(e.ModifiedTs),
	}
}
891370
func (c *commit) Proto() (ret *git.Commit, err error) {
	ret = &git.Commit{
		Id:       c.Commit,
		Tree:     c.Tree,
		Parents:  c.Parents,
		Message:  c.Message,
		TreeDiff: c.TreeDiff,
	}

	if ret.Author, err = c.Author.Proto(); err != nil {
		err = errors.Annotate(err, "decoding author").Err()
		return
	}
	if ret.Committer, err = c.Committer.Proto(); err != nil {
		err = errors.Annotate(err, "decoding committer").Err()
		return
	}

	return
}
58450
func (r *PURuntime) PortMap() map[nat.Port][]string {
	r.Lock()
	defer r.Unlock()

	if r.options != nil {
		return r.options.PortMap
	}

	return nil
}
1125728
func (res *Resolver) Serve(proto string) (<-chan struct{}, <-chan error) {
	defer util.HandleCrash()

	ch := make(chan struct{})
	server := &dns.Server{
		Addr:              net.JoinHostPort(res.config.Listener, strconv.Itoa(res.config.Port)),
		Net:               proto,
		TsigSecret:        nil,
		NotifyStartedFunc: func() { close(ch) },
	}

	errCh := make(chan error, 1)
	go func() {
		defer close(errCh)
		err := server.ListenAndServe()
		if err != nil {
			errCh <- fmt.Errorf("failed to setup %q server: %v", proto, err)
		} else {
			logging.Error.Printf("Not listening/serving any more requests.")
		}
	}()
	return ch, errCh
}
631453
func (n *Network) PeerPort(p *Peer, portName PortName) uint16 {
	peerPorts := n.PortsByPeerID[p.ID()]
	Expect(peerPorts).NotTo(BeNil())
	return peerPorts[portName]
}
809718
func (p *Project) Port(ctx context.Context, index int, protocol, serviceName, privatePort string) (string, error) {
	service, err := p.CreateService(serviceName)
	if err != nil {
		return "", err
	}

	containers, err := service.Containers(ctx)
	if err != nil {
		return "", err
	}

	if index < 1 || index > len(containers) {
		return "", fmt.Errorf("Invalid index %d", index)
	}

	return containers[index-1].Port(ctx, fmt.Sprintf("%s/%s", privatePort, protocol))
}
429990
func parsePorts(ports []networkingv1.NetworkPolicyPort) []api.PortRule {
	portRules := []api.PortRule{}
	for _, port := range ports {
		if port.Protocol == nil && port.Port == nil {
			continue
		}

		protocol := api.ProtoTCP
		if port.Protocol != nil {
			protocol, _ = api.ParseL4Proto(string(*port.Protocol))
		}

		portStr := ""
		if port.Port != nil {
			portStr = port.Port.String()
		}

		portRule := api.PortRule{
			Ports: []api.PortProtocol{
				{Port: portStr, Protocol: protocol},
			},
		}

		portRules = append(portRules, portRule)
	}

	return portRules
}