forked from alistairking/bgpfinder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdumptype_enumer.go
80 lines (65 loc) · 2.03 KB
/
dumptype_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
// Code generated by "enumer -type=DumpType -json -text -linecomment"; DO NOT EDIT.
package bgpfinder
import (
"encoding/json"
"fmt"
)
const _DumpTypeName = "anyribupdates"
var _DumpTypeIndex = [...]uint8{0, 3, 6, 13}
func (i DumpType) String() string {
if i >= DumpType(len(_DumpTypeIndex)-1) {
return fmt.Sprintf("DumpType(%d)", i)
}
return _DumpTypeName[_DumpTypeIndex[i]:_DumpTypeIndex[i+1]]
}
var _DumpTypeValues = []DumpType{0, 1, 2}
var _DumpTypeNameToValueMap = map[string]DumpType{
_DumpTypeName[0:3]: 0,
_DumpTypeName[3:6]: 1,
_DumpTypeName[6:13]: 2,
}
// DumpTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func DumpTypeString(s string) (DumpType, error) {
if val, ok := _DumpTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to DumpType values", s)
}
// DumpTypeValues returns all values of the enum
func DumpTypeValues() []DumpType {
return _DumpTypeValues
}
// IsADumpType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i DumpType) IsADumpType() bool {
for _, v := range _DumpTypeValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for DumpType
func (i DumpType) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for DumpType
func (i *DumpType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("DumpType should be a string, got %s", data)
}
var err error
*i, err = DumpTypeString(s)
return err
}
// MarshalText implements the encoding.TextMarshaler interface for DumpType
func (i DumpType) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for DumpType
func (i *DumpType) UnmarshalText(text []byte) error {
var err error
*i, err = DumpTypeString(string(text))
return err
}