aboutsummaryrefslogtreecommitdiff
path: root/src/protobuf/wkt/struct_pb.nim
blob: bf3f07df8c396ebd0e67992a38c4a9f3a8d1c06c (plain)
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# Generated by protoc_gen_nim. Do not edit!

import intsets
import tables
export tables

import protobuf/protobuf

type
    google_protobuf_NullValue* {.pure.} = enum
        NULL_VALUE = 0
    google_protobuf_Struct* = ref google_protobuf_StructObj
    google_protobuf_StructObj* = object of RootObj
        hasField: IntSet
        fields: TableRef[string, google_protobuf_Value]
    google_protobuf_Struct_FieldsEntry* = ref google_protobuf_Struct_FieldsEntryObj
    google_protobuf_Struct_FieldsEntryObj* = object of RootObj
        hasField: IntSet
        key: string
        value: google_protobuf_Value
    google_protobuf_Value* = ref google_protobuf_ValueObj
    google_protobuf_ValueObj* = object of RootObj
        hasField: IntSet
        kind: google_protobuf_Value_kind_OneOf

    google_protobuf_Value_kind_OneOf* {.union.} = object
        null_value: google_protobuf_NullValue
        number_value: float64
        string_value: string
        bool_value: bool
        struct_value: google_protobuf_Struct
        list_value: google_protobuf_ListValue
    google_protobuf_ListValue* = ref google_protobuf_ListValueObj
    google_protobuf_ListValueObj* = object of RootObj
        hasField: IntSet
        values: seq[google_protobuf_Value]

proc readgoogle_protobuf_NullValue*(stream: ProtobufStream): google_protobuf_NullValue =
    google_protobuf_NullValue(readUInt32(stream))

proc writegoogle_protobuf_NullValue*(stream: ProtobufStream, value: google_protobuf_NullValue) =
    writeUInt32(stream, uint32(value))

proc sizeOfgoogle_protobuf_NullValue*(value: google_protobuf_NullValue): uint64 =
    sizeOfUInt32(uint32(value))

proc newgoogle_protobuf_Struct_FieldsEntry*(): google_protobuf_Struct_FieldsEntry
proc writegoogle_protobuf_Struct_FieldsEntry*(stream: ProtobufStream, message: google_protobuf_Struct_FieldsEntry)
proc readgoogle_protobuf_Struct_FieldsEntry*(stream: ProtobufStream): google_protobuf_Struct_FieldsEntry
proc sizeOfgoogle_protobuf_Struct_FieldsEntry*(message: google_protobuf_Struct_FieldsEntry): uint64
proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, key: string, value: google_protobuf_Value)
proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, 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 writegoogle_protobuf_Struct*(stream: ProtobufStream, message: google_protobuf_Struct)
proc readgoogle_protobuf_Struct*(stream: ProtobufStream): google_protobuf_Struct
proc sizeOfgoogle_protobuf_Struct*(message: google_protobuf_Struct): uint64

proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue
proc writegoogle_protobuf_ListValue*(stream: ProtobufStream, message: google_protobuf_ListValue)
proc readgoogle_protobuf_ListValue*(stream: ProtobufStream): google_protobuf_ListValue
proc sizeOfgoogle_protobuf_ListValue*(message: google_protobuf_ListValue): uint64

proc newgoogle_protobuf_Value*(): google_protobuf_Value
proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobuf_Value)
proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value
proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64

proc newgoogle_protobuf_Struct_FieldsEntry*(): google_protobuf_Struct_FieldsEntry =
    new(result)
    result.hasField = initIntSet()
    result.key = ""
    result.value = nil

proc clearkey*(message: google_protobuf_Struct_FieldsEntry) =
    message.key = ""
    excl(message.hasField, 1)

proc haskey*(message: google_protobuf_Struct_FieldsEntry): bool =
    result = contains(message.hasField, 1)

proc setkey*(message: google_protobuf_Struct_FieldsEntry, value: string) =
    message.key = value
    incl(message.hasField, 1)

proc key*(message: google_protobuf_Struct_FieldsEntry): string {.inline.} =
    message.key

proc `key=`*(message: google_protobuf_Struct_FieldsEntry, value: string) {.inline.} =
    setkey(message, value)

proc clearvalue*(message: google_protobuf_Struct_FieldsEntry) =
    message.value = nil
    excl(message.hasField, 2)

proc hasvalue*(message: google_protobuf_Struct_FieldsEntry): bool =
    result = contains(message.hasField, 2)

proc setvalue*(message: google_protobuf_Struct_FieldsEntry, value: google_protobuf_Value) =
    message.value = value
    incl(message.hasField, 2)

proc value*(message: google_protobuf_Struct_FieldsEntry): google_protobuf_Value {.inline.} =
    message.value

proc `value=`*(message: google_protobuf_Struct_FieldsEntry, value: google_protobuf_Value) {.inline.} =
    setvalue(message, value)

proc sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key: string, value: google_protobuf_Value): uint64 =
    result = result + sizeOfString(key)
    result = result + sizeOfUInt32(uint32(makeTag(1, WireType.LengthDelimited)))
    let valueSize = sizeOfgoogle_protobuf_Value(value)
    result = result + valueSize
    result = result + sizeOfUInt32(uint32(makeTag(2, WireType.LengthDelimited)))
    result = result + sizeOfUInt64(valueSize)

proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, key: string, value: google_protobuf_Value) =
    writeTag(stream, 1, WireType.LengthDelimited)
    writeString(stream, key)
    writeTag(stream, 2, WireType.LengthDelimited)
    writeVarint(stream, sizeOfgoogle_protobuf_Value(value))
    writegoogle_protobuf_Value(stream, value)

proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, 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 = getTagWireType(tag)
        case getTagFieldNumber(tag)
        of 1:
            key = readString(stream)
            gotKey = true
        of 2:
            let
                size = readVarint(stream)
                data = safeReadStr(stream, int(size))
                pbs = newProtobufStream(newStringStream(data))
            value = readgoogle_protobuf_Value(pbs)
            gotValue = true
        else: skipField(stream, wireType)
    if not gotKey:
        raise newException(Exception, "missing key (google_protobuf_Struct_FieldsEntry)")
    if not gotValue:
        raise newException(Exception, "missing value (google_protobuf_Struct_FieldsEntry)")
    tbl[key] = value

proc sizeOfgoogle_protobuf_Struct_FieldsEntry*(message: google_protobuf_Struct_FieldsEntry): uint64 =
    if haskey(message):
        let
            sizeOfField = sizeOfString(message.key)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(1, WireType.LengthDelimited)))
        result = result + sizeOfField + sizeOfTag
    if hasvalue(message):
        let
            sizeOfField = sizeOfgoogle_protobuf_Value(message.value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(2, WireType.LengthDelimited)))
        result = result + sizeOfField + sizeOfTag
        result = result + sizeOfUInt64(sizeOfField)

proc writegoogle_protobuf_Struct_FieldsEntry*(stream: ProtobufStream, message: google_protobuf_Struct_FieldsEntry) =
    if haskey(message):
        writeTag(stream, 1, WireType.LengthDelimited)
        writeString(stream, message.key)
    if hasvalue(message):
        writeTag(stream, 2, WireType.LengthDelimited)
        writeVarint(stream, sizeOfgoogle_protobuf_Value(message.value))
        writegoogle_protobuf_Value(stream, message.value)

proc readgoogle_protobuf_Struct_FieldsEntry*(stream: ProtobufStream): google_protobuf_Struct_FieldsEntry =
    result = newgoogle_protobuf_Struct_FieldsEntry()
    while not atEnd(stream):
        let
            tag = readTag(stream)
            wireType = getTagWireType(tag)
        case getTagFieldNumber(tag)
        of 0:
            raise newException(InvalidFieldNumberError, "Invalid field number: 0")
        of 1:
            expectWireType(wireType, WireType.LengthDelimited)
            setkey(result, readString(stream))
        of 2:
            expectWireType(wireType, WireType.LengthDelimited)
            let
                size = readVarint(stream)
                data = safeReadStr(stream, int(size))
                pbs = newProtobufStream(newStringStream(data))
            setvalue(result, readgoogle_protobuf_Value(pbs))
        else: skipField(stream, wireType)

proc serialize*(message: google_protobuf_Struct_FieldsEntry): string =
    let
        ss = newStringStream()
        pbs = newProtobufStream(ss)
    writegoogle_protobuf_Struct_FieldsEntry(pbs, message)
    result = ss.data

proc newgoogle_protobuf_Struct_FieldsEntry*(data: string): google_protobuf_Struct_FieldsEntry =
    let
        ss = newStringStream(data)
        pbs = newProtobufStream(ss)
    result = readgoogle_protobuf_Struct_FieldsEntry(pbs)


proc newgoogle_protobuf_Struct*(): google_protobuf_Struct =
    new(result)
    result.hasField = initIntSet()
    result.fields = newTable[string, google_protobuf_Value]()

proc clearfields*(message: google_protobuf_Struct) =
    message.fields = newTable[string, google_protobuf_Value]()
    excl(message.hasField, 1)

proc hasfields*(message: google_protobuf_Struct): bool =
    result = contains(message.hasField, 1)

proc setfields*(message: google_protobuf_Struct, value: TableRef[string, google_protobuf_Value]) =
    message.fields = value
    incl(message.hasField, 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)
        let sizeOfTag = sizeOfUInt32(uint32(makeTag(1, WireType.LengthDelimited)))
        result = result + sizeOfKV + sizeOfTag + sizeOfUInt64(sizeOfKV)

proc writegoogle_protobuf_Struct*(stream: ProtobufStream, 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)

proc readgoogle_protobuf_Struct*(stream: ProtobufStream): google_protobuf_Struct =
    result = newgoogle_protobuf_Struct()
    while not atEnd(stream):
        let
            tag = readTag(stream)
            wireType = getTagWireType(tag)
        case getTagFieldNumber(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 = newProtobufStream(newStringStream(data))
            readgoogle_protobuf_Struct_FieldsEntryKV(pbs, result.fields)
        else: skipField(stream, wireType)

proc serialize*(message: google_protobuf_Struct): string =
    let
        ss = newStringStream()
        pbs = newProtobufStream(ss)
    writegoogle_protobuf_Struct(pbs, message)
    result = ss.data

proc newgoogle_protobuf_Struct*(data: string): google_protobuf_Struct =
    let
        ss = newStringStream(data)
        pbs = newProtobufStream(ss)
    result = readgoogle_protobuf_Struct(pbs)


proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue =
    new(result)
    result.hasField = initIntSet()
    result.values = @[]

proc clearvalues*(message: google_protobuf_ListValue) =
    message.values = @[]
    excl(message.hasField, 1)

proc hasvalues*(message: google_protobuf_ListValue): bool =
    result = contains(message.hasField, 1)

proc setvalues*(message: google_protobuf_ListValue, value: seq[google_protobuf_Value]) =
    message.values = value
    incl(message.hasField, 1)

proc addvalues*(message: google_protobuf_ListValue, value: google_protobuf_Value) =
    add(message.values, value)
    incl(message.hasField, 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:
        let
            sizeOfValue = sizeOfgoogle_protobuf_Value(value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(1, WireType.LengthDelimited)))
        result = result + sizeOfValue + sizeOfTag
    
        result = result + sizeOfUInt64(sizeOfValue)

proc writegoogle_protobuf_ListValue*(stream: ProtobufStream, message: google_protobuf_ListValue) =
    for value in message.values:
        writeTag(stream, 1, WireType.LengthDelimited)
        writeVarint(stream, sizeOfgoogle_protobuf_Value(value))
        writegoogle_protobuf_Value(stream, value)

proc readgoogle_protobuf_ListValue*(stream: ProtobufStream): google_protobuf_ListValue =
    result = newgoogle_protobuf_ListValue()
    while not atEnd(stream):
        let
            tag = readTag(stream)
            wireType = getTagWireType(tag)
        case getTagFieldNumber(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 = newProtobufStream(newStringStream(data))
            addvalues(result, readgoogle_protobuf_Value(pbs))
        else: skipField(stream, wireType)

proc serialize*(message: google_protobuf_ListValue): string =
    let
        ss = newStringStream()
        pbs = newProtobufStream(ss)
    writegoogle_protobuf_ListValue(pbs, message)
    result = ss.data

proc newgoogle_protobuf_ListValue*(data: string): google_protobuf_ListValue =
    let
        ss = newStringStream(data)
        pbs = newProtobufStream(ss)
    result = readgoogle_protobuf_ListValue(pbs)


proc newgoogle_protobuf_Value*(): google_protobuf_Value =
    new(result)
    result.hasField = initIntSet()
    result.kind.null_value = google_protobuf_NullValue(0)
    result.kind.number_value = 0
    result.kind.string_value = ""
    result.kind.bool_value = false
    result.kind.struct_value = nil
    result.kind.list_value = nil

proc clearnull_value*(message: google_protobuf_Value) =
    message.kind.null_value = google_protobuf_NullValue(0)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc hasnull_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 1)

proc setnull_value*(message: google_protobuf_Value, value: google_protobuf_NullValue) =
    message.kind.null_value = value
    incl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc null_value*(message: google_protobuf_Value): google_protobuf_NullValue {.inline.} =
    message.kind.null_value

proc `null_value=`*(message: google_protobuf_Value, value: google_protobuf_NullValue) {.inline.} =
    setnull_value(message, value)

proc clearnumber_value*(message: google_protobuf_Value) =
    message.kind.number_value = 0
    excl(message.hasField, 2)
    excl(message.hasField, 1)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc hasnumber_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 2)

proc setnumber_value*(message: google_protobuf_Value, value: float64) =
    message.kind.number_value = value
    incl(message.hasField, 2)
    excl(message.hasField, 1)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc number_value*(message: google_protobuf_Value): float64 {.inline.} =
    message.kind.number_value

proc `number_value=`*(message: google_protobuf_Value, value: float64) {.inline.} =
    setnumber_value(message, value)

proc clearstring_value*(message: google_protobuf_Value) =
    message.kind.string_value = ""
    excl(message.hasField, 3)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc hasstring_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 3)

proc setstring_value*(message: google_protobuf_Value, value: string) =
    message.kind.string_value = value
    incl(message.hasField, 3)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 4)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc string_value*(message: google_protobuf_Value): string {.inline.} =
    message.kind.string_value

proc `string_value=`*(message: google_protobuf_Value, value: string) {.inline.} =
    setstring_value(message, value)

proc clearbool_value*(message: google_protobuf_Value) =
    message.kind.bool_value = false
    excl(message.hasField, 4)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc hasbool_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 4)

proc setbool_value*(message: google_protobuf_Value, value: bool) =
    message.kind.bool_value = value
    incl(message.hasField, 4)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 5)
    excl(message.hasField, 6)

proc bool_value*(message: google_protobuf_Value): bool {.inline.} =
    message.kind.bool_value

proc `bool_value=`*(message: google_protobuf_Value, value: bool) {.inline.} =
    setbool_value(message, value)

proc clearstruct_value*(message: google_protobuf_Value) =
    message.kind.struct_value = nil
    excl(message.hasField, 5)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 6)

proc hasstruct_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 5)

proc setstruct_value*(message: google_protobuf_Value, value: google_protobuf_Struct) =
    message.kind.struct_value = value
    incl(message.hasField, 5)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 6)

proc struct_value*(message: google_protobuf_Value): google_protobuf_Struct {.inline.} =
    message.kind.struct_value

proc `struct_value=`*(message: google_protobuf_Value, value: google_protobuf_Struct) {.inline.} =
    setstruct_value(message, value)

proc clearlist_value*(message: google_protobuf_Value) =
    message.kind.list_value = nil
    excl(message.hasField, 6)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)

proc haslist_value*(message: google_protobuf_Value): bool =
    result = contains(message.hasField, 6)

proc setlist_value*(message: google_protobuf_Value, value: google_protobuf_ListValue) =
    message.kind.list_value = value
    incl(message.hasField, 6)
    excl(message.hasField, 1)
    excl(message.hasField, 2)
    excl(message.hasField, 3)
    excl(message.hasField, 4)
    excl(message.hasField, 5)

proc list_value*(message: google_protobuf_Value): google_protobuf_ListValue {.inline.} =
    message.kind.list_value

proc `list_value=`*(message: google_protobuf_Value, value: google_protobuf_ListValue) {.inline.} =
    setlist_value(message, value)

proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 =
    if hasnull_value(message):
        let
            sizeOfField = sizeOfgoogle_protobuf_NullValue(message.kind.null_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(1, WireType.Varint)))
        result = result + sizeOfField + sizeOfTag
    if hasnumber_value(message):
        let
            sizeOfField = sizeOfDouble(message.kind.number_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(2, WireType.Fixed64)))
        result = result + sizeOfField + sizeOfTag
    if hasstring_value(message):
        let
            sizeOfField = sizeOfString(message.kind.string_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(3, WireType.LengthDelimited)))
        result = result + sizeOfField + sizeOfTag
    if hasbool_value(message):
        let
            sizeOfField = sizeOfBool(message.kind.bool_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(4, WireType.Varint)))
        result = result + sizeOfField + sizeOfTag
    if hasstruct_value(message):
        let
            sizeOfField = sizeOfgoogle_protobuf_Struct(message.kind.struct_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(5, WireType.LengthDelimited)))
        result = result + sizeOfField + sizeOfTag
        result = result + sizeOfUInt64(sizeOfField)
    if haslist_value(message):
        let
            sizeOfField = sizeOfgoogle_protobuf_ListValue(message.kind.list_value)
            sizeOfTag = sizeOfUInt32(uint32(makeTag(6, WireType.LengthDelimited)))
        result = result + sizeOfField + sizeOfTag
        result = result + sizeOfUInt64(sizeOfField)

proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobuf_Value) =
    if hasnull_value(message):
        writeTag(stream, 1, WireType.Varint)
        writegoogle_protobuf_NullValue(stream, message.kind.null_value)
    if hasnumber_value(message):
        writeTag(stream, 2, WireType.Fixed64)
        writeDouble(stream, message.kind.number_value)
    if hasstring_value(message):
        writeTag(stream, 3, WireType.LengthDelimited)
        writeString(stream, message.kind.string_value)
    if hasbool_value(message):
        writeTag(stream, 4, WireType.Varint)
        writeBool(stream, message.kind.bool_value)
    if hasstruct_value(message):
        writeTag(stream, 5, WireType.LengthDelimited)
        writeVarint(stream, sizeOfgoogle_protobuf_Struct(message.kind.struct_value))
        writegoogle_protobuf_Struct(stream, message.kind.struct_value)
    if haslist_value(message):
        writeTag(stream, 6, WireType.LengthDelimited)
        writeVarint(stream, sizeOfgoogle_protobuf_ListValue(message.kind.list_value))
        writegoogle_protobuf_ListValue(stream, message.kind.list_value)

proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value =
    result = newgoogle_protobuf_Value()
    while not atEnd(stream):
        let
            tag = readTag(stream)
            wireType = getTagWireType(tag)
        case getTagFieldNumber(tag)
        of 0:
            raise newException(InvalidFieldNumberError, "Invalid field number: 0")
        of 1:
            expectWireType(wireType, WireType.Varint)
            setnull_value(result, readgoogle_protobuf_NullValue(stream))
        of 2:
            expectWireType(wireType, WireType.Fixed64)
            setnumber_value(result, readDouble(stream))
        of 3:
            expectWireType(wireType, WireType.LengthDelimited)
            setstring_value(result, readString(stream))
        of 4:
            expectWireType(wireType, WireType.Varint)
            setbool_value(result, readBool(stream))
        of 5:
            expectWireType(wireType, WireType.LengthDelimited)
            let
                size = readVarint(stream)
                data = safeReadStr(stream, int(size))
                pbs = newProtobufStream(newStringStream(data))
            setstruct_value(result, readgoogle_protobuf_Struct(pbs))
        of 6:
            expectWireType(wireType, WireType.LengthDelimited)
            let
                size = readVarint(stream)
                data = safeReadStr(stream, int(size))
                pbs = newProtobufStream(newStringStream(data))
            setlist_value(result, readgoogle_protobuf_ListValue(pbs))
        else: skipField(stream, wireType)

proc serialize*(message: google_protobuf_Value): string =
    let
        ss = newStringStream()
        pbs = newProtobufStream(ss)
    writegoogle_protobuf_Value(pbs, message)
    result = ss.data

proc newgoogle_protobuf_Value*(data: string): google_protobuf_Value =
    let
        ss = newStringStream(data)
        pbs = newProtobufStream(ss)
    result = readgoogle_protobuf_Value(pbs)