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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
# Generated by protoc_gen_nim. Do not edit!
import base64
import intsets
import json
import tables
export tables
import nimpb/nimpb
import nimpb/json as nimpb_json
type
google_protobuf_NullValue* {.pure.} = enum
NULL_VALUE = 0
google_protobuf_Struct* = ref google_protobuf_StructObj
google_protobuf_StructObj* = object of Message
fields: TableRef[string, google_protobuf_Value]
google_protobuf_Value* = ref google_protobuf_ValueObj
google_protobuf_ValueObj* = object of Message
kind: google_protobuf_Value_kind_OneOf
google_protobuf_Value_kind_OneOf* {.union.} = object
nullValue: google_protobuf_NullValue
numberValue: float64
stringValue: string
boolValue: bool
structValue: google_protobuf_Struct
listValue: google_protobuf_ListValue
google_protobuf_ListValue* = ref google_protobuf_ListValueObj
google_protobuf_ListValueObj* = object of Message
values: seq[google_protobuf_Value]
proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: Stream, key: string, value: google_protobuf_Value)
proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: Stream, tbl: TableRef[string, google_protobuf_Value])
proc sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key: string, value: google_protobuf_Value): uint64
proc newgoogle_protobuf_Struct*(): google_protobuf_Struct
proc newgoogle_protobuf_Struct*(data: string): google_protobuf_Struct
proc newgoogle_protobuf_Struct*(data: seq[byte]): google_protobuf_Struct
proc writegoogle_protobuf_Struct*(stream: Stream, message: google_protobuf_Struct)
proc readgoogle_protobuf_Struct*(stream: Stream): google_protobuf_Struct
proc sizeOfgoogle_protobuf_Struct*(message: google_protobuf_Struct): uint64
proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue
proc newgoogle_protobuf_ListValue*(data: string): google_protobuf_ListValue
proc newgoogle_protobuf_ListValue*(data: seq[byte]): google_protobuf_ListValue
proc writegoogle_protobuf_ListValue*(stream: Stream, message: google_protobuf_ListValue)
proc readgoogle_protobuf_ListValue*(stream: Stream): google_protobuf_ListValue
proc sizeOfgoogle_protobuf_ListValue*(message: google_protobuf_ListValue): uint64
proc newgoogle_protobuf_Value*(): google_protobuf_Value
proc newgoogle_protobuf_Value*(data: string): google_protobuf_Value
proc newgoogle_protobuf_Value*(data: seq[byte]): google_protobuf_Value
proc writegoogle_protobuf_Value*(stream: Stream, message: google_protobuf_Value)
proc readgoogle_protobuf_Value*(stream: Stream): google_protobuf_Value
proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64
proc sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key: string, value: google_protobuf_Value): uint64 =
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfString(key)
result = result + sizeOfTag(2, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Value(value))
proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: Stream, key: string, value: google_protobuf_Value) =
protoWriteString(stream, key, 1)
writeMessage(stream, value, 2)
proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: Stream, tbl: TableRef[string, google_protobuf_Value]) =
var
key: string
gotKey = false
value: google_protobuf_Value
gotValue = false
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 1:
key = protoReadString(stream)
gotKey = true
of 2:
let
size = readVarint(stream)
data = safeReadStr(stream, int(size))
pbs = newStringStream(data)
value = readgoogle_protobuf_Value(pbs)
gotValue = true
else: skipField(stream, wireType)
if not gotKey:
raise newException(Exception, "missing key")
if not gotValue:
raise newException(Exception, "missing value")
tbl[key] = value
proc newgoogle_protobuf_Struct*(): google_protobuf_Struct =
new(result)
initMessage(result[])
result.fields = newTable[string, google_protobuf_Value]()
proc clearfields*(message: google_protobuf_Struct) =
message.fields = newTable[string, google_protobuf_Value]()
clearFields(message, [1])
proc hasfields*(message: google_protobuf_Struct): bool =
result = hasField(message, 1) or (len(message.fields) > 0)
proc setfields*(message: google_protobuf_Struct, value: TableRef[string, google_protobuf_Value]) =
message.fields = value
setField(message, 1)
proc fields*(message: google_protobuf_Struct): TableRef[string, google_protobuf_Value] {.inline.} =
message.fields
proc `fields=`*(message: google_protobuf_Struct, value: TableRef[string, google_protobuf_Value]) {.inline.} =
setfields(message, value)
proc sizeOfgoogle_protobuf_Struct*(message: google_protobuf_Struct): uint64 =
if hasfields(message):
var sizeOfKV = 0'u64
for key, value in message.fields:
sizeOfKV = sizeOfKV + sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key, value)
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfKV)
result = result + sizeOfUnknownFields(message)
proc writegoogle_protobuf_Struct*(stream: Stream, message: google_protobuf_Struct) =
for key, value in message.fields:
writeTag(stream, 1, WireType.LengthDelimited)
writeVarint(stream, sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key, value))
writegoogle_protobuf_Struct_FieldsEntryKV(stream, key, value)
writeUnknownFields(stream, message)
proc readgoogle_protobuf_Struct*(stream: Stream): google_protobuf_Struct =
result = newgoogle_protobuf_Struct()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.LengthDelimited)
let
size = readVarint(stream)
data = safeReadStr(stream, int(size))
pbs = newStringStream(data)
readgoogle_protobuf_Struct_FieldsEntryKV(pbs, result.fields)
else: readUnknownField(stream, result, tag)
proc serialize*(message: google_protobuf_Struct): string =
let
ss = newStringStream()
writegoogle_protobuf_Struct(ss, message)
result = ss.data
proc newgoogle_protobuf_Struct*(data: string): google_protobuf_Struct =
let
ss = newStringStream(data)
result = readgoogle_protobuf_Struct(ss)
proc newgoogle_protobuf_Struct*(data: seq[byte]): google_protobuf_Struct =
let
ss = newStringStream(cast[string](data))
result = readgoogle_protobuf_Struct(ss)
proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue =
new(result)
initMessage(result[])
result.values = @[]
proc clearvalues*(message: google_protobuf_ListValue) =
message.values = @[]
clearFields(message, [1])
proc hasvalues*(message: google_protobuf_ListValue): bool =
result = hasField(message, 1) or (len(message.values) > 0)
proc setvalues*(message: google_protobuf_ListValue, value: seq[google_protobuf_Value]) =
message.values = value
setField(message, 1)
proc addvalues*(message: google_protobuf_ListValue, value: google_protobuf_Value) =
add(message.values, value)
setField(message, 1)
proc values*(message: google_protobuf_ListValue): seq[google_protobuf_Value] {.inline.} =
message.values
proc `values=`*(message: google_protobuf_ListValue, value: seq[google_protobuf_Value]) {.inline.} =
setvalues(message, value)
proc sizeOfgoogle_protobuf_ListValue*(message: google_protobuf_ListValue): uint64 =
for value in message.values:
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Value(value))
result = result + sizeOfUnknownFields(message)
proc writegoogle_protobuf_ListValue*(stream: Stream, message: google_protobuf_ListValue) =
for value in message.values:
writeMessage(stream, value, 1)
writeUnknownFields(stream, message)
proc readgoogle_protobuf_ListValue*(stream: Stream): google_protobuf_ListValue =
result = newgoogle_protobuf_ListValue()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.LengthDelimited)
let data = readLengthDelimited(stream)
addvalues(result, newgoogle_protobuf_Value(data))
else: readUnknownField(stream, result, tag)
proc serialize*(message: google_protobuf_ListValue): string =
let
ss = newStringStream()
writegoogle_protobuf_ListValue(ss, message)
result = ss.data
proc newgoogle_protobuf_ListValue*(data: string): google_protobuf_ListValue =
let
ss = newStringStream(data)
result = readgoogle_protobuf_ListValue(ss)
proc newgoogle_protobuf_ListValue*(data: seq[byte]): google_protobuf_ListValue =
let
ss = newStringStream(cast[string](data))
result = readgoogle_protobuf_ListValue(ss)
proc newgoogle_protobuf_Value*(): google_protobuf_Value =
new(result)
initMessage(result[])
result.kind.nullValue = google_protobuf_NullValue.NULL_VALUE
result.kind.numberValue = 0
result.kind.stringValue = ""
result.kind.boolValue = false
result.kind.structValue = nil
result.kind.listValue = nil
proc clearnullValue*(message: google_protobuf_Value) =
message.kind.nullValue = google_protobuf_NullValue.NULL_VALUE
clearFields(message, [1, 2, 3, 4, 5, 6])
proc hasnullValue*(message: google_protobuf_Value): bool =
result = hasField(message, 1)
proc setnullValue*(message: google_protobuf_Value, value: google_protobuf_NullValue) =
message.kind.nullValue = value
setField(message, 1)
clearFields(message, [2, 3, 4, 5, 6])
proc nullValue*(message: google_protobuf_Value): google_protobuf_NullValue {.inline.} =
message.kind.nullValue
proc `nullValue=`*(message: google_protobuf_Value, value: google_protobuf_NullValue) {.inline.} =
setnullValue(message, value)
proc clearnumberValue*(message: google_protobuf_Value) =
message.kind.numberValue = 0
clearFields(message, [2, 1, 3, 4, 5, 6])
proc hasnumberValue*(message: google_protobuf_Value): bool =
result = hasField(message, 2)
proc setnumberValue*(message: google_protobuf_Value, value: float64) =
message.kind.numberValue = value
setField(message, 2)
clearFields(message, [1, 3, 4, 5, 6])
proc numberValue*(message: google_protobuf_Value): float64 {.inline.} =
message.kind.numberValue
proc `numberValue=`*(message: google_protobuf_Value, value: float64) {.inline.} =
setnumberValue(message, value)
proc clearstringValue*(message: google_protobuf_Value) =
message.kind.stringValue = ""
clearFields(message, [3, 1, 2, 4, 5, 6])
proc hasstringValue*(message: google_protobuf_Value): bool =
result = hasField(message, 3)
proc setstringValue*(message: google_protobuf_Value, value: string) =
message.kind.stringValue = value
setField(message, 3)
clearFields(message, [1, 2, 4, 5, 6])
proc stringValue*(message: google_protobuf_Value): string {.inline.} =
message.kind.stringValue
proc `stringValue=`*(message: google_protobuf_Value, value: string) {.inline.} =
setstringValue(message, value)
proc clearboolValue*(message: google_protobuf_Value) =
message.kind.boolValue = false
clearFields(message, [4, 1, 2, 3, 5, 6])
proc hasboolValue*(message: google_protobuf_Value): bool =
result = hasField(message, 4)
proc setboolValue*(message: google_protobuf_Value, value: bool) =
message.kind.boolValue = value
setField(message, 4)
clearFields(message, [1, 2, 3, 5, 6])
proc boolValue*(message: google_protobuf_Value): bool {.inline.} =
message.kind.boolValue
proc `boolValue=`*(message: google_protobuf_Value, value: bool) {.inline.} =
setboolValue(message, value)
proc clearstructValue*(message: google_protobuf_Value) =
message.kind.structValue = nil
clearFields(message, [5, 1, 2, 3, 4, 6])
proc hasstructValue*(message: google_protobuf_Value): bool =
result = hasField(message, 5)
proc setstructValue*(message: google_protobuf_Value, value: google_protobuf_Struct) =
message.kind.structValue = value
setField(message, 5)
clearFields(message, [1, 2, 3, 4, 6])
proc structValue*(message: google_protobuf_Value): google_protobuf_Struct {.inline.} =
message.kind.structValue
proc `structValue=`*(message: google_protobuf_Value, value: google_protobuf_Struct) {.inline.} =
setstructValue(message, value)
proc clearlistValue*(message: google_protobuf_Value) =
message.kind.listValue = nil
clearFields(message, [6, 1, 2, 3, 4, 5])
proc haslistValue*(message: google_protobuf_Value): bool =
result = hasField(message, 6)
proc setlistValue*(message: google_protobuf_Value, value: google_protobuf_ListValue) =
message.kind.listValue = value
setField(message, 6)
clearFields(message, [1, 2, 3, 4, 5])
proc listValue*(message: google_protobuf_Value): google_protobuf_ListValue {.inline.} =
message.kind.listValue
proc `listValue=`*(message: google_protobuf_Value, value: google_protobuf_ListValue) {.inline.} =
setlistValue(message, value)
proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 =
if hasnullValue(message):
result = result + sizeOfTag(1, WireType.Varint)
result = result + sizeOfEnum[google_protobuf_NullValue](message.kind.nullValue)
if hasnumberValue(message):
result = result + sizeOfTag(2, WireType.Fixed64)
result = result + sizeOfDouble(message.kind.numberValue)
if hasstringValue(message):
result = result + sizeOfTag(3, WireType.LengthDelimited)
result = result + sizeOfString(message.kind.stringValue)
if hasboolValue(message):
result = result + sizeOfTag(4, WireType.Varint)
result = result + sizeOfBool(message.kind.boolValue)
if hasstructValue(message):
result = result + sizeOfTag(5, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Struct(message.kind.structValue))
if haslistValue(message):
result = result + sizeOfTag(6, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_ListValue(message.kind.listValue))
result = result + sizeOfUnknownFields(message)
proc writegoogle_protobuf_Value*(stream: Stream, message: google_protobuf_Value) =
if hasnullValue(message):
protoWriteEnum(stream, message.kind.nullValue, 1)
if hasnumberValue(message):
protoWriteDouble(stream, message.kind.numberValue, 2)
if hasstringValue(message):
protoWriteString(stream, message.kind.stringValue, 3)
if hasboolValue(message):
protoWriteBool(stream, message.kind.boolValue, 4)
if hasstructValue(message):
writeMessage(stream, message.kind.structValue, 5)
if haslistValue(message):
writeMessage(stream, message.kind.listValue, 6)
writeUnknownFields(stream, message)
proc readgoogle_protobuf_Value*(stream: Stream): google_protobuf_Value =
result = newgoogle_protobuf_Value()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.Varint)
setnullValue(result, protoReadEnum[google_protobuf_NullValue](stream))
of 2:
expectWireType(wireType, WireType.Fixed64)
setnumberValue(result, protoReadDouble(stream))
of 3:
expectWireType(wireType, WireType.LengthDelimited)
setstringValue(result, protoReadString(stream))
of 4:
expectWireType(wireType, WireType.Varint)
setboolValue(result, protoReadBool(stream))
of 5:
expectWireType(wireType, WireType.LengthDelimited)
let data = readLengthDelimited(stream)
setstructValue(result, newgoogle_protobuf_Struct(data))
of 6:
expectWireType(wireType, WireType.LengthDelimited)
let data = readLengthDelimited(stream)
setlistValue(result, newgoogle_protobuf_ListValue(data))
else: readUnknownField(stream, result, tag)
proc serialize*(message: google_protobuf_Value): string =
let
ss = newStringStream()
writegoogle_protobuf_Value(ss, message)
result = ss.data
proc newgoogle_protobuf_Value*(data: string): google_protobuf_Value =
let
ss = newStringStream(data)
result = readgoogle_protobuf_Value(ss)
proc newgoogle_protobuf_Value*(data: seq[byte]): google_protobuf_Value =
let
ss = newStringStream(cast[string](data))
result = readgoogle_protobuf_Value(ss)
|