Debian Codegraph @

port.go

raw
1 // This file is part of pluggable-discovery-protocol-handler.
2 //
3 // SPDX-FileCopyrightText: Arduino s.r.l. and/or its affiliated companies
4 // SPDX-License-Identifier: GPL-3.0-or-later
5
6 package discovery
7
8 import "github.com/arduino/go-properties-orderedmap"
9
10 // Port is a descriptor for a board port
11 type Port struct {
12 Address string `json:"address"`
13 AddressLabel string `json:"label,omitempty"`
14 Protocol string `json:"protocol,omitempty"`
15 ProtocolLabel string `json:"protocolLabel,omitempty"`
16 Properties *properties.Map `json:"properties,omitempty"`
17 HardwareID string `json:"hardwareId,omitempty"`
18 }
19
20 // Equals returns true if the given port has the same address and protocol
21 // of the current port.
22 func (p *Port) Equals(o *Port) bool {
23 return p.Address == o.Address && p.Protocol == o.Protocol
24 }
25
26 func (p *Port) String() string {
27 if p == nil {
28 return "none"
29 }
30 return p.Address
31 }
32
33 // Clone creates a copy of this Port
34 func (p *Port) Clone() *Port {
35 if p == nil {
36 return nil
37 }
38 res := *p
39 if p.Properties != nil {
40 res.Properties = p.Properties.Clone()
41 }
42 return &res
43 }