/
alias_types.go
314 lines (281 loc) · 11.2 KB
/
alias_types.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Copyright 2020 Buf Technologies, Inc.
//
// 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 protosource
import (
"fmt"
"strconv"
"google.golang.org/protobuf/types/descriptorpb"
)
const (
// FieldDescriptorProtoTypeDouble is an alias.
FieldDescriptorProtoTypeDouble FieldDescriptorProtoType = 1
// FieldDescriptorProtoTypeFloat is an alias.
FieldDescriptorProtoTypeFloat FieldDescriptorProtoType = 2
// FieldDescriptorProtoTypeInt64 is an alias.
FieldDescriptorProtoTypeInt64 FieldDescriptorProtoType = 3
// FieldDescriptorProtoTypeUint64 is an alias.
FieldDescriptorProtoTypeUint64 FieldDescriptorProtoType = 4
// FieldDescriptorProtoTypeInt32 is an alias.
FieldDescriptorProtoTypeInt32 FieldDescriptorProtoType = 5
// FieldDescriptorProtoTypeFixed64 is an alias.
FieldDescriptorProtoTypeFixed64 FieldDescriptorProtoType = 6
// FieldDescriptorProtoTypeFixed32 is an alias.
FieldDescriptorProtoTypeFixed32 FieldDescriptorProtoType = 7
// FieldDescriptorProtoTypeBool is an alias.
FieldDescriptorProtoTypeBool FieldDescriptorProtoType = 8
// FieldDescriptorProtoTypeString is an alias.
FieldDescriptorProtoTypeString FieldDescriptorProtoType = 9
// FieldDescriptorProtoTypeGroup is an alias.
FieldDescriptorProtoTypeGroup FieldDescriptorProtoType = 10
// FieldDescriptorProtoTypeMessage is an alias.
FieldDescriptorProtoTypeMessage FieldDescriptorProtoType = 11
// FieldDescriptorProtoTypeBytes is an alias.
FieldDescriptorProtoTypeBytes FieldDescriptorProtoType = 12
// FieldDescriptorProtoTypeUint32 is an alias.
FieldDescriptorProtoTypeUint32 FieldDescriptorProtoType = 13
// FieldDescriptorProtoTypeEnum is an alias.
FieldDescriptorProtoTypeEnum FieldDescriptorProtoType = 14
// FieldDescriptorProtoTypeSfixed32 is an alias.
FieldDescriptorProtoTypeSfixed32 FieldDescriptorProtoType = 15
// FieldDescriptorProtoTypeSfixed64 is an alias.
FieldDescriptorProtoTypeSfixed64 FieldDescriptorProtoType = 16
// FieldDescriptorProtoTypeSint32 is an alias.
FieldDescriptorProtoTypeSint32 FieldDescriptorProtoType = 17
// FieldDescriptorProtoTypeSint64 is an alias.
FieldDescriptorProtoTypeSint64 FieldDescriptorProtoType = 18
// FieldDescriptorProtoLabelOptional is an alias.
FieldDescriptorProtoLabelOptional FieldDescriptorProtoLabel = 1
// FieldDescriptorProtoLabelRequired is an alias.
FieldDescriptorProtoLabelRequired FieldDescriptorProtoLabel = 2
// FieldDescriptorProtoLabelRepeated is an alias.
FieldDescriptorProtoLabelRepeated FieldDescriptorProtoLabel = 3
// FieldOptionsCTypeString is an alias.
FieldOptionsCTypeString FieldOptionsCType = 0
// FieldOptionsCTypeCord is an alias.
FieldOptionsCTypeCord FieldOptionsCType = 1
// FieldOptionsCTypeStringPiece is an alias.
FieldOptionsCTypeStringPiece FieldOptionsCType = 2
// FieldOptionsJSTypeJSNormal is an alias.
FieldOptionsJSTypeJSNormal FieldOptionsJSType = 0
// FieldOptionsJSTypeJSString is an alias.
FieldOptionsJSTypeJSString FieldOptionsJSType = 1
// FieldOptionsJSTypeJSNumber is an alias.
FieldOptionsJSTypeJSNumber FieldOptionsJSType = 2
// FileOptionsOptimizeModeSpeed is an alias.
FileOptionsOptimizeModeSpeed FileOptionsOptimizeMode = 1
// FileOptionsOptimizeModeCodeSize is an alias.
FileOptionsOptimizeModeCodeSize FileOptionsOptimizeMode = 2
// FileOptionsOptimizeModeLiteRuntime is an alias.
FileOptionsOptimizeModeLiteRuntime FileOptionsOptimizeMode = 3
// MethodOptionsIdempotencyLevelIdempotencyUnknown is an alias.
MethodOptionsIdempotencyLevelIdempotencyUnknown = 0
// MethodOptionsIdempotencyLevelNoSideEffects is an alias.
MethodOptionsIdempotencyLevelNoSideEffects = 1
// MethodOptionsIdempotencyLevelIdempotent is an alias.
MethodOptionsIdempotencyLevelIdempotent = 2
)
var (
numberToFieldDescriptorProtoType = map[int32]FieldDescriptorProtoType{
1: FieldDescriptorProtoTypeDouble,
2: FieldDescriptorProtoTypeFloat,
3: FieldDescriptorProtoTypeInt64,
4: FieldDescriptorProtoTypeUint64,
5: FieldDescriptorProtoTypeInt32,
6: FieldDescriptorProtoTypeFixed64,
7: FieldDescriptorProtoTypeFixed32,
8: FieldDescriptorProtoTypeBool,
9: FieldDescriptorProtoTypeString,
10: FieldDescriptorProtoTypeGroup,
11: FieldDescriptorProtoTypeMessage,
12: FieldDescriptorProtoTypeBytes,
13: FieldDescriptorProtoTypeUint32,
14: FieldDescriptorProtoTypeEnum,
15: FieldDescriptorProtoTypeSfixed32,
16: FieldDescriptorProtoTypeSfixed64,
17: FieldDescriptorProtoTypeSint32,
18: FieldDescriptorProtoTypeSint64,
}
fieldDescriptorProtoTypeToString = map[FieldDescriptorProtoType]string{
FieldDescriptorProtoTypeDouble: "double",
FieldDescriptorProtoTypeFloat: "float",
FieldDescriptorProtoTypeInt64: "int64",
FieldDescriptorProtoTypeUint64: "uint64",
FieldDescriptorProtoTypeInt32: "int32",
FieldDescriptorProtoTypeFixed64: "fixed64",
FieldDescriptorProtoTypeFixed32: "fixed32",
FieldDescriptorProtoTypeBool: "bool",
FieldDescriptorProtoTypeString: "string",
FieldDescriptorProtoTypeGroup: "group",
FieldDescriptorProtoTypeMessage: "message",
FieldDescriptorProtoTypeBytes: "bytes",
FieldDescriptorProtoTypeUint32: "uint32",
FieldDescriptorProtoTypeEnum: "enum",
FieldDescriptorProtoTypeSfixed32: "sfixed32",
FieldDescriptorProtoTypeSfixed64: "sfixed64",
FieldDescriptorProtoTypeSint32: "sint32",
FieldDescriptorProtoTypeSint64: "sint64",
}
numberToFieldDescriptorProtoLabel = map[int32]FieldDescriptorProtoLabel{
1: FieldDescriptorProtoLabelOptional,
2: FieldDescriptorProtoLabelRequired,
3: FieldDescriptorProtoLabelRepeated,
}
fieldDescriptorProtoLabelToString = map[FieldDescriptorProtoLabel]string{
FieldDescriptorProtoLabelOptional: "optional",
FieldDescriptorProtoLabelRequired: "required",
FieldDescriptorProtoLabelRepeated: "repeated",
}
numberToFieldOptionsCType = map[int32]FieldOptionsCType{
0: FieldOptionsCTypeString,
1: FieldOptionsCTypeCord,
2: FieldOptionsCTypeStringPiece,
}
fieldOptionsCTypeToString = map[FieldOptionsCType]string{
FieldOptionsCTypeString: "STRING",
FieldOptionsCTypeCord: "CORD",
FieldOptionsCTypeStringPiece: "STRING_PIECE",
}
numberToFieldOptionsJSType = map[int32]FieldOptionsJSType{
0: FieldOptionsJSTypeJSNormal,
1: FieldOptionsJSTypeJSString,
2: FieldOptionsJSTypeJSNumber,
}
fieldOptionsJSTypeToString = map[FieldOptionsJSType]string{
FieldOptionsJSTypeJSNormal: "JS_NORMAL",
FieldOptionsJSTypeJSString: "JS_STRING",
FieldOptionsJSTypeJSNumber: "JS_NUMBER",
}
numberToFileOptionsOptimizeMode = map[int32]FileOptionsOptimizeMode{
1: FileOptionsOptimizeModeSpeed,
2: FileOptionsOptimizeModeCodeSize,
3: FileOptionsOptimizeModeLiteRuntime,
}
fileOptionsOptimizeModeToString = map[FileOptionsOptimizeMode]string{
FileOptionsOptimizeModeSpeed: "SPEED",
FileOptionsOptimizeModeCodeSize: "CODE_SIZE",
FileOptionsOptimizeModeLiteRuntime: "LITE_RUNTIME",
}
numberToMethodOptionsIdempotencyLevel = map[int32]MethodOptionsIdempotencyLevel{
0: MethodOptionsIdempotencyLevelIdempotencyUnknown,
1: MethodOptionsIdempotencyLevelNoSideEffects,
2: MethodOptionsIdempotencyLevelIdempotent,
}
methodOptionsIdempotencyLevelToString = map[MethodOptionsIdempotencyLevel]string{
MethodOptionsIdempotencyLevelIdempotencyUnknown: "IDEMPOTENCY_UNKNOWN",
MethodOptionsIdempotencyLevelNoSideEffects: "NO_SIDE_EFFECTS",
MethodOptionsIdempotencyLevelIdempotent: "IDEMPOTENT",
}
)
// FieldDescriptorProtoType aliases descriptorpb.FieldDescriptorProto_Type.
type FieldDescriptorProtoType int32
// String returns the string representation of the FieldDescriptorProtoType.
func (t FieldDescriptorProtoType) String() string {
s, ok := fieldDescriptorProtoTypeToString[t]
if !ok {
return strconv.Itoa(int(t))
}
return s
}
func getFieldDescriptorProtoType(v descriptorpb.FieldDescriptorProto_Type) (FieldDescriptorProtoType, error) {
t, ok := numberToFieldDescriptorProtoType[int32(v)]
if !ok {
return 0, fmt.Errorf("no FieldDescriptorProtoType for %v", v)
}
return t, nil
}
// FieldDescriptorProtoLabel aliases descriptorpb.FieldDescriptorProto_Label.
type FieldDescriptorProtoLabel int32
// String returns the string representation of the FieldDescriptorProtoLabel.
func (l FieldDescriptorProtoLabel) String() string {
s, ok := fieldDescriptorProtoLabelToString[l]
if !ok {
return strconv.Itoa(int(l))
}
return s
}
func getFieldDescriptorProtoLabel(v descriptorpb.FieldDescriptorProto_Label) (FieldDescriptorProtoLabel, error) {
t, ok := numberToFieldDescriptorProtoLabel[int32(v)]
if !ok {
return 0, fmt.Errorf("no FieldDescriptorProtoLabel for %v", v)
}
return t, nil
}
// FieldOptionsCType aliases descriptorpb.FieldOptions_CType.
type FieldOptionsCType int32
// String returns the string representation of the FieldOptionsCType.
func (c FieldOptionsCType) String() string {
s, ok := fieldOptionsCTypeToString[c]
if !ok {
return strconv.Itoa(int(c))
}
return s
}
func getFieldOptionsCType(v descriptorpb.FieldOptions_CType) (FieldOptionsCType, error) {
t, ok := numberToFieldOptionsCType[int32(v)]
if !ok {
return 0, fmt.Errorf("no FieldOptionsCType for %v", v)
}
return t, nil
}
// FieldOptionsJSType aliases descriptorpb.FieldOptions_JSType.
type FieldOptionsJSType int32
// String returns the string representation of the FieldOptionsJSType.
func (j FieldOptionsJSType) String() string {
s, ok := fieldOptionsJSTypeToString[j]
if !ok {
return strconv.Itoa(int(j))
}
return s
}
func getFieldOptionsJSType(v descriptorpb.FieldOptions_JSType) (FieldOptionsJSType, error) {
t, ok := numberToFieldOptionsJSType[int32(v)]
if !ok {
return 0, fmt.Errorf("no FieldOptionsJSType for %v", v)
}
return t, nil
}
// FileOptionsOptimizeMode aliases descriptorpb.FileOptions_OptimizeMode.
type FileOptionsOptimizeMode int32
// String returns the string representation of the FileOptionsOptimizeMode.
func (t FileOptionsOptimizeMode) String() string {
s, ok := fileOptionsOptimizeModeToString[t]
if !ok {
return strconv.Itoa(int(t))
}
return s
}
func getFileOptionsOptimizeMode(v descriptorpb.FileOptions_OptimizeMode) (FileOptionsOptimizeMode, error) {
t, ok := numberToFileOptionsOptimizeMode[int32(v)]
if !ok {
return 0, fmt.Errorf("no FileOptionsOptimizeMode for %v", v)
}
return t, nil
}
// MethodOptionsIdempotencyLevel aliases descriptorpb.MethodOptions_IdempotencyLevel.
type MethodOptionsIdempotencyLevel int32
// String returns the string representation of the MethodOptionsIdempotencyLevel.
func (t MethodOptionsIdempotencyLevel) String() string {
s, ok := methodOptionsIdempotencyLevelToString[t]
if !ok {
return strconv.Itoa(int(t))
}
return s
}
func getMethodOptionsIdempotencyLevel(v descriptorpb.MethodOptions_IdempotencyLevel) (MethodOptionsIdempotencyLevel, error) {
t, ok := numberToMethodOptionsIdempotencyLevel[int32(v)]
if !ok {
return 0, fmt.Errorf("no MethodOptionsIdempotencyLevel for %v", v)
}
return t, nil
}