-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_instance_state.go
127 lines (110 loc) · 3.07 KB
/
enum_instance_state.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package clccam
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// State of an instance or a machine.
type InstanceState uint32
const (
InstanceState_processing InstanceState = iota
InstanceState_done
InstanceState_unavailable
)
// Implements encoding.TextMarshaler
func (i InstanceState) MarshalText() ([]byte, error) {
switch i {
case InstanceState_processing:
return []byte("processing"), nil
case InstanceState_done:
return []byte("done"), nil
case InstanceState_unavailable:
return []byte("unavailable"), nil
}
return nil, fmt.Errorf("invalid InstanceState %d", i)
}
// Implements fmt.Stringer
func (i InstanceState) String() string {
if b, err := i.MarshalText(); err != nil {
return err.Error()
} else {
return string(b)
}
}
// Implements encoding.TextUnmarshaler
func (i *InstanceState) UnmarshalText(data []byte) error {
switch string(data) {
case "processing":
*i = InstanceState_processing
case "done":
*i = InstanceState_done
case "unavailable":
*i = InstanceState_unavailable
default:
return fmt.Errorf("invalid InstanceState %q", string(data))
}
return nil
}
// Implements flag.Value
func (i *InstanceState) Set(s string) error {
return i.UnmarshalText([]byte(s))
}
// Implements pflag.Value (superset of flag.Value)
func (i InstanceState) Type() string {
return "InstanceState"
}
// InstanceStateFromString attempts to parse @s as stringified InstanceState.
func InstanceStateFromString(s string) (val InstanceState, err error) {
return val, val.Set(s)
}
// InstanceStateStrings returns the list of InstanceState string literals, or maps @vals if non-empty.
func InstanceStateStrings(vals ...InstanceState) (ret []string) {
if len(vals) > 0 {
for _, val := range vals {
ret = append(ret, val.String())
}
return ret
}
return []string{"processing", "done", "unavailable"}
}
// Implements database/sql/driver.Valuer
func (i InstanceState) Value() (driver.Value, error) {
return i.String(), nil
}
// Implements database/sql.Scanner
func (i *InstanceState) Scan(src interface{}) error {
switch src := src.(type) {
case int64:
*i = InstanceState(src)
return nil
case []byte:
return i.UnmarshalText(src)
case string:
return i.UnmarshalText([]byte(src))
}
return fmt.Errorf("unable to convert %T to InstanceState", src)
}
// Implements json.Marshaler
func (i InstanceState) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// Implements json.Unmarshaler
func (i *InstanceState) UnmarshalJSON(data []byte) error {
var output string
if err := json.Unmarshal(data, &output); err != nil {
return fmt.Errorf("failed to parse '%s' as InstanceState: %s", string(data), err)
}
return i.UnmarshalText([]byte(output))
}
// Implements yaml.Marshaler
func (i InstanceState) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// Implements yaml.Unmarshaler
func (i *InstanceState) UnmarshalYAML(unmarshal func(interface{}) error) error {
var output string
if err := unmarshal(&output); err != nil {
return fmt.Errorf("failed to unmarshal InstanceState from YAML: %s", err)
}
return i.UnmarshalText([]byte(output))
}