Switch for enums
This commit is contained in:
parent
cbe0a56aef
commit
088b1d1a93
2 changed files with 40 additions and 20 deletions
|
@ -36,12 +36,18 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f Function) String() string {
|
func (f Function) String() string {
|
||||||
return map[Function]string{
|
switch f {
|
||||||
FunctionBrRq: "BrRq",
|
case FunctionBrRq:
|
||||||
FunctionLkUp: "LkUp",
|
return "BrRq"
|
||||||
FunctionLkUpReply: "LkUp-Reply",
|
case FunctionLkUp:
|
||||||
FunctionFwdReq: "FwdReq",
|
return "LkUp"
|
||||||
}[f]
|
case FunctionLkUpReply:
|
||||||
|
return "LkUp-Reply"
|
||||||
|
case FunctionFwdReq:
|
||||||
|
return "FwdReq"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packet represents an NBP packet.
|
// Packet represents an NBP packet.
|
||||||
|
|
|
@ -48,13 +48,20 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rs receiverState) String() string {
|
func (rs receiverState) String() string {
|
||||||
return map[receiverState]string{
|
switch rs {
|
||||||
rsUnconnected: "unconnected",
|
case rsUnconnected:
|
||||||
rsConnected: "connected",
|
return "unconnected"
|
||||||
rsWaitForOpenRsp: "waiting for Open-Rsp",
|
case rsConnected:
|
||||||
rsWaitForRIRsp: "waiting for RI-Rsp",
|
return "connected"
|
||||||
rsWaitForTickleAck: "waiting for Tickle-Ack",
|
case rsWaitForOpenRsp:
|
||||||
}[rs]
|
return "waiting for Open-Rsp"
|
||||||
|
case rsWaitForRIRsp:
|
||||||
|
return "waiting for RI-Rsp"
|
||||||
|
case rsWaitForTickleAck:
|
||||||
|
return "waiting for Tickle-Ack"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type senderState int
|
type senderState int
|
||||||
|
@ -68,13 +75,20 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ss senderState) String() string {
|
func (ss senderState) String() string {
|
||||||
return map[senderState]string{
|
switch ss {
|
||||||
ssUnconnected: "unconnected",
|
case ssUnconnected:
|
||||||
ssConnected: "connected",
|
return "unconnected"
|
||||||
ssWaitForRIRspAck: "waiting for RI-Ack for RI-Rsp",
|
case ssConnected:
|
||||||
ssWaitForRIUpdAck: "waiting for RI-Ack for RI-Upd",
|
return "connected"
|
||||||
ssWaitForRDAck: "waiting for RI-Ack for RD",
|
case ssWaitForRIRspAck:
|
||||||
}[ss]
|
return "waiting for RI-Ack for RI-Rsp"
|
||||||
|
case ssWaitForRIUpdAck:
|
||||||
|
return "waiting for RI-Ack for RI-Upd"
|
||||||
|
case ssWaitForRDAck:
|
||||||
|
return "waiting for RI-Ack for RD"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
|
|
Loading…
Reference in a new issue