-
Notifications
You must be signed in to change notification settings - Fork 2
/
ledmode_jsonenums.go
62 lines (55 loc) · 1.5 KB
/
ledmode_jsonenums.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
// generated by jsonenums -type=ledMode; DO NOT EDIT
package xethru
import (
"encoding/json"
"fmt"
)
var (
_ledModeNameToValue = map[string]ledMode{
"LEDOff": LEDOff,
"LEDSimple": LEDSimple,
"LEDFull": LEDFull,
"LEDInhalation": LEDInhalation,
}
_ledModeValueToName = map[ledMode]string{
LEDOff: "LEDOff",
LEDSimple: "LEDSimple",
LEDFull: "LEDFull",
LEDInhalation: "LEDInhalation",
}
)
func init() {
var v ledMode
if _, ok := interface{}(v).(fmt.Stringer); ok {
_ledModeNameToValue = map[string]ledMode{
interface{}(LEDOff).(fmt.Stringer).String(): LEDOff,
interface{}(LEDSimple).(fmt.Stringer).String(): LEDSimple,
interface{}(LEDFull).(fmt.Stringer).String(): LEDFull,
interface{}(LEDInhalation).(fmt.Stringer).String(): LEDInhalation,
}
}
}
// MarshalJSON is generated so ledMode satisfies json.Marshaler.
func (r ledMode) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _ledModeValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid ledMode: %d", r)
}
return json.Marshal(s)
}
// UnmarshalJSON is generated so ledMode satisfies json.Unmarshaler.
func (r *ledMode) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("ledMode should be a string, got %s", data)
}
v, ok := _ledModeNameToValue[s]
if !ok {
return fmt.Errorf("invalid ledMode %q", s)
}
*r = v
return nil
}