Switch for enums

This commit is contained in:
Josh Deprez 2024-04-26 14:37:38 +10:00
parent cbe0a56aef
commit 088b1d1a93
No known key found for this signature in database
2 changed files with 40 additions and 20 deletions

View file

@ -36,12 +36,18 @@ const (
)
func (f Function) String() string {
return map[Function]string{
FunctionBrRq: "BrRq",
FunctionLkUp: "LkUp",
FunctionLkUpReply: "LkUp-Reply",
FunctionFwdReq: "FwdReq",
}[f]
switch f {
case FunctionBrRq:
return "BrRq"
case FunctionLkUp:
return "LkUp"
case FunctionLkUpReply:
return "LkUp-Reply"
case FunctionFwdReq:
return "FwdReq"
default:
return "unknown"
}
}
// Packet represents an NBP packet.

View file

@ -48,13 +48,20 @@ const (
)
func (rs receiverState) String() string {
return map[receiverState]string{
rsUnconnected: "unconnected",
rsConnected: "connected",
rsWaitForOpenRsp: "waiting for Open-Rsp",
rsWaitForRIRsp: "waiting for RI-Rsp",
rsWaitForTickleAck: "waiting for Tickle-Ack",
}[rs]
switch rs {
case rsUnconnected:
return "unconnected"
case rsConnected:
return "connected"
case rsWaitForOpenRsp:
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
@ -68,13 +75,20 @@ const (
)
func (ss senderState) String() string {
return map[senderState]string{
ssUnconnected: "unconnected",
ssConnected: "connected",
ssWaitForRIRspAck: "waiting for RI-Ack for RI-Rsp",
ssWaitForRIUpdAck: "waiting for RI-Ack for RI-Upd",
ssWaitForRDAck: "waiting for RI-Ack for RD",
}[ss]
switch ss {
case ssUnconnected:
return "unconnected"
case ssConnected:
return "connected"
case ssWaitForRIRspAck:
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 {