-
Notifications
You must be signed in to change notification settings - Fork 1
/
protocol_enumer.go
90 lines (73 loc) · 2.18 KB
/
protocol_enumer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Code generated by "enumer -type=Protocol -text"; DO NOT EDIT.
package flags
import (
"fmt"
"strings"
)
const _ProtocolName = "SubTCP"
var _ProtocolIndex = [...]uint8{0, 3, 6}
const _ProtocolLowerName = "subtcp"
func (i Protocol) String() string {
if i >= Protocol(len(_ProtocolIndex)-1) {
return fmt.Sprintf("Protocol(%d)", i)
}
return _ProtocolName[_ProtocolIndex[i]:_ProtocolIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _ProtocolNoOp() {
var x [1]struct{}
_ = x[Sub-(0)]
_ = x[TCP-(1)]
}
var _ProtocolValues = []Protocol{Sub, TCP}
var _ProtocolNameToValueMap = map[string]Protocol{
_ProtocolName[0:3]: Sub,
_ProtocolLowerName[0:3]: Sub,
_ProtocolName[3:6]: TCP,
_ProtocolLowerName[3:6]: TCP,
}
var _ProtocolNames = []string{
_ProtocolName[0:3],
_ProtocolName[3:6],
}
// ProtocolString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ProtocolString(s string) (Protocol, error) {
if val, ok := _ProtocolNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _ProtocolNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Protocol values", s)
}
// ProtocolValues returns all values of the enum
func ProtocolValues() []Protocol {
return _ProtocolValues
}
// ProtocolStrings returns a slice of all String values of the enum
func ProtocolStrings() []string {
strs := make([]string, len(_ProtocolNames))
copy(strs, _ProtocolNames)
return strs
}
// IsAProtocol returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Protocol) IsAProtocol() bool {
for _, v := range _ProtocolValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Protocol
func (i Protocol) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Protocol
func (i *Protocol) UnmarshalText(text []byte) error {
var err error
*i, err = ProtocolString(string(text))
return err
}