-
Notifications
You must be signed in to change notification settings - Fork 302
/
enums.go
237 lines (214 loc) · 6.92 KB
/
enums.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ttnpb
import (
"strconv"
"strings"
"github.com/gogo/protobuf/jsonpb"
)
// MarshalText implements encoding.TextMarshaler interface.
func (v DownlinkPathConstraint) MarshalText() ([]byte, error) {
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler interface.
func (v *DownlinkPathConstraint) UnmarshalText(b []byte) error {
s := string(b)
if i, ok := DownlinkPathConstraint_value[s]; ok {
*v = DownlinkPathConstraint(i)
return nil
}
if !strings.HasPrefix(s, "DOWNLINK_PATH_CONSTRAINT_") {
if i, ok := DownlinkPathConstraint_value["DOWNLINK_PATH_CONSTRAINT_"+s]; ok {
*v = DownlinkPathConstraint(i)
return nil
}
}
return errCouldNotParse("DownlinkPathConstraint")(string(b))
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (v *DownlinkPathConstraint) UnmarshalJSON(b []byte) error {
if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
return v.UnmarshalText(b[1 : len(b)-1])
}
i, err := strconv.Atoi(string(b))
if err != nil {
return errCouldNotParse("DownlinkPathConstraint")(string(b)).WithCause(err)
}
*v = DownlinkPathConstraint(i)
return nil
}
// MarshalText implements encoding.TextMarshaler interface.
func (v State) MarshalText() ([]byte, error) {
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler interface.
func (v *State) UnmarshalText(b []byte) error {
s := string(b)
if i, ok := State_value[s]; ok {
*v = State(i)
return nil
}
if !strings.HasPrefix(s, "STATE_") {
if i, ok := State_value["STATE_"+s]; ok {
*v = State(i)
return nil
}
}
return errCouldNotParse("State")(string(b))
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (v *State) UnmarshalJSON(b []byte) error {
if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
return v.UnmarshalText(b[1 : len(b)-1])
}
i, err := strconv.Atoi(string(b))
if err != nil {
return errCouldNotParse("State")(string(b)).WithCause(err)
}
*v = State(i)
return nil
}
// MarshalText implements encoding.TextMarshaler interface.
func (v KeyProvisioning) MarshalText() ([]byte, error) {
switch v {
case KeyProvisioning_KEY_PROVISIONING_UNKNOWN:
return []byte("unknown"), nil
case KeyProvisioning_KEY_PROVISIONING_CUSTOM:
return []byte("custom"), nil
case KeyProvisioning_KEY_PROVISIONING_JOIN_SERVER:
return []byte("join server"), nil
case KeyProvisioning_KEY_PROVISIONING_MANIFEST:
return []byte("manifest"), nil
}
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaller interface.
func (v *KeyProvisioning) UnmarshalText(b []byte) error {
s := string(b)
if i, ok := KeyProvisioning_value[s]; ok {
*v = KeyProvisioning(i)
return nil
}
switch s {
case "unknown", "KEY_PROVISIONING_UNKNOWN":
*v = KeyProvisioning_KEY_PROVISIONING_UNKNOWN
case "custom", "KEY_PROVISIONING_CUSTOM":
*v = KeyProvisioning_KEY_PROVISIONING_CUSTOM
case "join server", "KEY_PROVISIONING_JOIN_SERVER":
*v = KeyProvisioning_KEY_PROVISIONING_JOIN_SERVER
case "manifest", "KEY_PROVISIONING_MANIFEST":
*v = KeyProvisioning_KEY_PROVISIONING_MANIFEST
default:
errCouldNotParse("KeyProvisioning")(string(b))
}
return nil
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (v *KeyProvisioning) UnmarshalJSON(b []byte) error {
if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
return v.UnmarshalText(b[1 : len(b)-1])
}
i, err := strconv.Atoi(string(b))
if err != nil {
return errCouldNotParse("KeyProvisioning")(string(b)).WithCause(err)
}
*v = KeyProvisioning(i)
return nil
}
// UnmarshalJSONPB implements json.Unmarshaler interface.
func (v *KeyProvisioning) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, b []byte) error {
return v.UnmarshalJSON(b)
}
// MarshalText implements encoding.TextMarshaler interface.
func (v KeySecurity) MarshalText() ([]byte, error) {
switch v {
case KeySecurity_KEY_SECURITY_UNKNOWN:
return []byte("unknown"), nil
case KeySecurity_KEY_SECURITY_NONE:
return []byte("none"), nil
case KeySecurity_KEY_SECURITY_READ_PROTECTED:
return []byte("read protected"), nil
case KeySecurity_KEY_SECURITY_SECURE_ELEMENT:
return []byte("secure element"), nil
}
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaller interface.
func (v *KeySecurity) UnmarshalText(b []byte) error {
s := string(b)
if i, ok := KeySecurity_value[s]; ok {
*v = KeySecurity(i)
return nil
}
switch s {
case "unknown", "KEY_SECURITY_UNKNOWN":
*v = KeySecurity_KEY_SECURITY_UNKNOWN
case "none", "KEY_SECURITY_NONE":
*v = KeySecurity_KEY_SECURITY_NONE
case "read protected", "KEY_SECURITY_READ_PROTECTED":
*v = KeySecurity_KEY_SECURITY_READ_PROTECTED
case "secure element", "KEY_SECURITY_SECURE_ELEMENT":
*v = KeySecurity_KEY_SECURITY_SECURE_ELEMENT
default:
errCouldNotParse("KeySecurity")(string(b))
}
return nil
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (v *KeySecurity) UnmarshalJSON(b []byte) error {
if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
return v.UnmarshalText(b[1 : len(b)-1])
}
i, err := strconv.Atoi(string(b))
if err != nil {
return errCouldNotParse("KeySecurity")(string(b)).WithCause(err)
}
*v = KeySecurity(i)
return nil
}
// UnmarshalJSONPB implements json.Unmarshaler interface.
func (v *KeySecurity) UnmarshalJSONPB(u *jsonpb.Unmarshaler, b []byte) error {
return v.UnmarshalJSON(b)
}
// MarshalText implements encoding.TextMarshaler interface.
func (v GatewayAntennaPlacement) MarshalText() ([]byte, error) {
return []byte(v.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler interface.
func (v *GatewayAntennaPlacement) UnmarshalText(b []byte) error {
s := string(b)
if i, ok := GatewayAntennaPlacement_value[s]; ok {
*v = GatewayAntennaPlacement(i)
return nil
}
if !strings.HasPrefix(s, "PLACEMENT_") {
if i, ok := GatewayAntennaPlacement_value["PLACEMENT_"+s]; ok {
*v = GatewayAntennaPlacement(i)
return nil
}
}
return errCouldNotParse("GatewayAntennaPlacement")(string(b))
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (v *GatewayAntennaPlacement) UnmarshalJSON(b []byte) error {
if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
return v.UnmarshalText(b[1 : len(b)-1])
}
i, err := strconv.Atoi(string(b))
if err != nil {
return errCouldNotParse("GatewayAntennaPlacement")(string(b)).WithCause(err)
}
*v = GatewayAntennaPlacement(i)
return nil
}