/
rscperror_enumer.go
86 lines (73 loc) · 2.2 KB
/
rscperror_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
// Code generated by "enumer -type=RscpError -json"; DO NOT EDIT.
//
package rscp
import (
"encoding/json"
"fmt"
)
const (
_RscpErrorName_0 = "ERR_NOT_HANDLEDERR_ACCESS_DENIEDERR_FORMATERR_AGAINERR_OUT_OF_BOUNDSERR_NOT_AVAILABLEERR_UNKNOWN_TAGERR_ALREADY_IN_USE"
_RscpErrorName_1 = "ERR_UNEXPECTED"
)
var (
_RscpErrorIndex_0 = [...]uint8{0, 15, 32, 42, 51, 68, 85, 100, 118}
_RscpErrorIndex_1 = [...]uint8{0, 14}
)
func (i RscpError) String() string {
switch {
case 1 <= i && i <= 8:
i -= 1
return _RscpErrorName_0[_RscpErrorIndex_0[i]:_RscpErrorIndex_0[i+1]]
case i == 4294967295:
return _RscpErrorName_1
default:
return fmt.Sprintf("RscpError(%d)", i)
}
}
var _RscpErrorValues = []RscpError{1, 2, 3, 4, 5, 6, 7, 8, 4294967295}
var _RscpErrorNameToValueMap = map[string]RscpError{
_RscpErrorName_0[0:15]: 1,
_RscpErrorName_0[15:32]: 2,
_RscpErrorName_0[32:42]: 3,
_RscpErrorName_0[42:51]: 4,
_RscpErrorName_0[51:68]: 5,
_RscpErrorName_0[68:85]: 6,
_RscpErrorName_0[85:100]: 7,
_RscpErrorName_0[100:118]: 8,
_RscpErrorName_1[0:14]: 4294967295,
}
// RscpErrorString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func RscpErrorString(s string) (RscpError, error) {
if val, ok := _RscpErrorNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to RscpError values", s)
}
// RscpErrorValues returns all values of the enum
func RscpErrorValues() []RscpError {
return _RscpErrorValues
}
// IsARscpError returns "true" if the value is listed in the enum definition. "false" otherwise
func (i RscpError) IsARscpError() bool {
for _, v := range _RscpErrorValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for RscpError
func (i RscpError) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for RscpError
func (i *RscpError) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("RscpError should be a string, got %s", data)
}
var err error
*i, err = RscpErrorString(s)
return err
}