forked from rai-project/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout_enumer.go
136 lines (112 loc) · 2.9 KB
/
layout_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
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
127
128
129
130
131
132
133
134
135
136
// Code generated by "enumer -type=Layout -json -text -yaml -sql"; DO NOT EDIT.
package image
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
const (
_LayoutName_0 = "HWCLayoutCHWLayout"
_LayoutName_1 = "InvalidLayout"
)
var (
_LayoutIndex_0 = [...]uint8{0, 9, 18}
_LayoutIndex_1 = [...]uint8{0, 13}
)
func (i Layout) String() string {
switch {
case 0 <= i && i <= 1:
return _LayoutName_0[_LayoutIndex_0[i]:_LayoutIndex_0[i+1]]
case i == 9999:
return _LayoutName_1
default:
return fmt.Sprintf("Layout(%d)", i)
}
}
var _LayoutValues = []Layout{0, 1, 9999}
var _LayoutNameToValueMap = map[string]Layout{
_LayoutName_0[0:9]: 0,
_LayoutName_0[9:18]: 1,
_LayoutName_1[0:13]: 9999,
}
// LayoutString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func LayoutString(s string) (Layout, error) {
if val, ok := _LayoutNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Layout values", s)
}
// LayoutValues returns all values of the enum
func LayoutValues() []Layout {
return _LayoutValues
}
// IsALayout returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Layout) IsALayout() bool {
for _, v := range _LayoutValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for Layout
func (i Layout) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for Layout
func (i *Layout) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("Layout should be a string, got %s", data)
}
var err error
*i, err = LayoutString(s)
return err
}
// MarshalText implements the encoding.TextMarshaler interface for Layout
func (i Layout) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Layout
func (i *Layout) UnmarshalText(text []byte) error {
var err error
*i, err = LayoutString(string(text))
return err
}
// MarshalYAML implements a YAML Marshaler for Layout
func (i Layout) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// UnmarshalYAML implements a YAML Unmarshaler for Layout
func (i *Layout) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
var err error
*i, err = LayoutString(s)
return err
}
func (i Layout) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *Layout) Scan(value interface{}) error {
if value == nil {
return nil
}
str, ok := value.(string)
if !ok {
bytes, ok := value.([]byte)
if !ok {
return fmt.Errorf("value is not a byte slice")
}
str = string(bytes[:])
}
val, err := LayoutString(str)
if err != nil {
return err
}
*i = val
return nil
}