autobee 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,987 @@
1
+ // This file is autogenerated by the hyperschema compiler
2
+ // Schema Version: 1
3
+ /* eslint-disable camelcase */
4
+ /* eslint-disable quotes */
5
+ /* eslint-disable space-before-function-paren */
6
+
7
+ const { c } = require('hyperschema/runtime')
8
+ const external0 = require('../../legacy.js')
9
+
10
+ const VERSION = 1
11
+
12
+ // eslint-disable-next-line no-unused-vars
13
+ let version = VERSION
14
+
15
+ // @autobase-compat/checkout
16
+ const encoding0 = {
17
+ preencode(state, m) {
18
+ c.fixed32.preencode(state, m.key)
19
+ c.uint.preencode(state, m.length)
20
+ },
21
+ encode(state, m) {
22
+ c.fixed32.encode(state, m.key)
23
+ c.uint.encode(state, m.length)
24
+ },
25
+ decode(state) {
26
+ const r0 = c.fixed32.decode(state)
27
+ const r1 = c.uint.decode(state)
28
+
29
+ return {
30
+ key: r0,
31
+ length: r1
32
+ }
33
+ }
34
+ }
35
+
36
+ // @autobase-compat/clock
37
+ const encoding1 = c.array(encoding0)
38
+
39
+ // @autobase-compat/index-checkpoint
40
+ const encoding2 = {
41
+ preencode(state, m) {
42
+ c.fixed64.preencode(state, m.signature)
43
+ c.uint.preencode(state, m.length)
44
+ },
45
+ encode(state, m) {
46
+ c.fixed64.encode(state, m.signature)
47
+ c.uint.encode(state, m.length)
48
+ },
49
+ decode(state) {
50
+ const r0 = c.fixed64.decode(state)
51
+ const r1 = c.uint.decode(state)
52
+
53
+ return {
54
+ signature: r0,
55
+ length: r1
56
+ }
57
+ }
58
+ }
59
+
60
+ const encoding3 = external0.BootRecordV0
61
+
62
+ // @autobase-compat/boot-record-raw
63
+ const encoding4 = {
64
+ preencode(state, m) {
65
+ c.fixed32.preencode(state, m.key)
66
+ c.uint.preencode(state, m.systemLength)
67
+ state.end++ // max flag is 4 so always one byte
68
+
69
+ if (m.recoveries) c.uint.preencode(state, m.recoveries)
70
+ },
71
+ encode(state, m) {
72
+ const flags = (m.indexersUpdated ? 1 : 0) | (m.fastForwarding ? 2 : 0) | (m.recoveries ? 4 : 0)
73
+
74
+ c.fixed32.encode(state, m.key)
75
+ c.uint.encode(state, m.systemLength)
76
+ c.uint.encode(state, flags)
77
+
78
+ if (m.recoveries) c.uint.encode(state, m.recoveries)
79
+ },
80
+ decode(state) {
81
+ const v = c.uint.decode(state)
82
+ const r0 = c.fixed32.decode(state)
83
+ const r1 = c.uint.decode(state)
84
+ const flags = c.uint.decode(state)
85
+
86
+ return {
87
+ version: v,
88
+ key: r0,
89
+ systemLength: r1,
90
+ indexersUpdated: (flags & 1) !== 0,
91
+ fastForwarding: (flags & 2) !== 0,
92
+ recoveries: (flags & 4) !== 0 ? c.uint.decode(state) : 0
93
+ }
94
+ }
95
+ }
96
+
97
+ // @autobase-compat/boot-record
98
+ const encoding5 = {
99
+ preencode(state, m) {
100
+ c.uint.preencode(state, m.version)
101
+ switch (m.version) {
102
+ case 0:
103
+ encoding3.preencode(state, m)
104
+ break
105
+ case 1:
106
+ case 2:
107
+ case 3:
108
+ encoding4.preencode(state, m)
109
+ break
110
+ default:
111
+ throw new Error('Unsupported version')
112
+ }
113
+ },
114
+ encode(state, m) {
115
+ c.uint.encode(state, m.version)
116
+ switch (m.version) {
117
+ case 0:
118
+ encoding3.encode(state, m)
119
+ break
120
+ case 1:
121
+ case 2:
122
+ case 3:
123
+ encoding4.encode(state, m)
124
+ break
125
+ default:
126
+ throw new Error('Unsupported version')
127
+ }
128
+ },
129
+ decode(state) {
130
+ const start = state.start
131
+ const v = c.uint.decode(state)
132
+ state.start = start
133
+ switch (v) {
134
+ case 0: {
135
+ const decoded = encoding3.decode(state)
136
+ return decoded
137
+ }
138
+ case 1:
139
+ case 2:
140
+ case 3: {
141
+ const decoded = encoding4.decode(state)
142
+ return decoded
143
+ }
144
+ default:
145
+ throw new Error('Unsupported version')
146
+ }
147
+ }
148
+ }
149
+
150
+ // @autobase-compat/checkpointer
151
+ const encoding6 = {
152
+ preencode(state, m) {
153
+ state.end++ // flags are fixed size
154
+
155
+ if (m.checkpointer) c.uint.preencode(state, m.checkpointer)
156
+ if (m.checkpoint) encoding2.preencode(state, m.checkpoint)
157
+ },
158
+ encode(state, m) {
159
+ const flags = (m.checkpointer ? 1 : 0) | (m.checkpoint ? 2 : 0)
160
+
161
+ c.uint8.encode(state, flags)
162
+
163
+ if (m.checkpointer) c.uint.encode(state, m.checkpointer)
164
+ if (m.checkpoint) encoding2.encode(state, m.checkpoint)
165
+ },
166
+ decode(state) {
167
+ const flags = c.uint8.decode(state)
168
+
169
+ return {
170
+ checkpointer: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
171
+ checkpoint: (flags & 2) !== 0 ? encoding2.decode(state) : null
172
+ }
173
+ }
174
+ }
175
+
176
+ // @autobase-compat/checkpoint.user
177
+ const encoding7_2 = c.array(encoding6)
178
+
179
+ // @autobase-compat/checkpoint
180
+ const encoding7 = {
181
+ preencode(state, m) {
182
+ state.end++ // max flag is 4 so always one byte
183
+
184
+ if (m.system) encoding6.preencode(state, m.system)
185
+ if (m.encryption) encoding6.preencode(state, m.encryption)
186
+ if (m.user) encoding7_2.preencode(state, m.user)
187
+ },
188
+ encode(state, m) {
189
+ const flags = (m.system ? 1 : 0) | (m.encryption ? 2 : 0) | (m.user ? 4 : 0)
190
+
191
+ c.uint.encode(state, flags)
192
+
193
+ if (m.system) encoding6.encode(state, m.system)
194
+ if (m.encryption) encoding6.encode(state, m.encryption)
195
+ if (m.user) encoding7_2.encode(state, m.user)
196
+ },
197
+ decode(state) {
198
+ const flags = c.uint.decode(state)
199
+
200
+ return {
201
+ system: (flags & 1) !== 0 ? encoding6.decode(state) : null,
202
+ encryption: (flags & 2) !== 0 ? encoding6.decode(state) : null,
203
+ user: (flags & 4) !== 0 ? encoding7_2.decode(state) : null
204
+ }
205
+ }
206
+ }
207
+
208
+ // @autobase-compat/digest
209
+ const encoding8 = {
210
+ preencode(state, m) {
211
+ state.end++ // max flag is 2 so always one byte
212
+
213
+ if (m.pointer) c.uint.preencode(state, m.pointer)
214
+ if (m.key) c.fixed32.preencode(state, m.key)
215
+ },
216
+ encode(state, m) {
217
+ const flags = (m.pointer ? 1 : 0) | (m.key ? 2 : 0)
218
+
219
+ c.uint.encode(state, flags)
220
+
221
+ if (m.pointer) c.uint.encode(state, m.pointer)
222
+ if (m.key) c.fixed32.encode(state, m.key)
223
+ },
224
+ decode(state) {
225
+ const flags = c.uint.decode(state)
226
+
227
+ return {
228
+ pointer: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
229
+ key: (flags & 2) !== 0 ? c.fixed32.decode(state) : null
230
+ }
231
+ }
232
+ }
233
+
234
+ // @autobase-compat/node
235
+ const encoding9 = {
236
+ preencode(state, m) {
237
+ encoding1.preencode(state, m.heads)
238
+ c.uint.preencode(state, m.batch)
239
+ c.buffer.preencode(state, m.value)
240
+ },
241
+ encode(state, m) {
242
+ encoding1.encode(state, m.heads)
243
+ c.uint.encode(state, m.batch)
244
+ c.buffer.encode(state, m.value)
245
+ },
246
+ decode(state) {
247
+ const r0 = encoding1.decode(state)
248
+ const r1 = c.uint.decode(state)
249
+ const r2 = c.buffer.decode(state)
250
+
251
+ return {
252
+ heads: r0,
253
+ batch: r1,
254
+ value: r2
255
+ }
256
+ }
257
+ }
258
+
259
+ // @autobase-compat/user-view-trace.blocks
260
+ const encoding10_1 = c.array(c.uint)
261
+
262
+ // @autobase-compat/user-view-trace
263
+ const encoding10 = {
264
+ preencode(state, m) {
265
+ c.uint.preencode(state, m.view)
266
+ encoding10_1.preencode(state, m.blocks)
267
+ },
268
+ encode(state, m) {
269
+ c.uint.encode(state, m.view)
270
+ encoding10_1.encode(state, m.blocks)
271
+ },
272
+ decode(state) {
273
+ const r0 = c.uint.decode(state)
274
+ const r1 = encoding10_1.decode(state)
275
+
276
+ return {
277
+ view: r0,
278
+ blocks: r1
279
+ }
280
+ }
281
+ }
282
+
283
+ // @autobase-compat/trace.system
284
+ const encoding11_0 = encoding10_1
285
+ // @autobase-compat/trace.encryption
286
+ const encoding11_1 = encoding10_1
287
+ // @autobase-compat/trace.user
288
+ const encoding11_2 = c.array(encoding10)
289
+
290
+ // @autobase-compat/trace
291
+ const encoding11 = {
292
+ preencode(state, m) {
293
+ encoding11_0.preencode(state, m.system)
294
+ encoding11_1.preencode(state, m.encryption)
295
+ encoding11_2.preencode(state, m.user)
296
+ },
297
+ encode(state, m) {
298
+ encoding11_0.encode(state, m.system)
299
+ encoding11_1.encode(state, m.encryption)
300
+ encoding11_2.encode(state, m.user)
301
+ },
302
+ decode(state) {
303
+ const r0 = encoding11_0.decode(state)
304
+ const r1 = encoding11_1.decode(state)
305
+ const r2 = encoding11_2.decode(state)
306
+
307
+ return {
308
+ system: r0,
309
+ encryption: r1,
310
+ user: r2
311
+ }
312
+ }
313
+ }
314
+
315
+ const encoding12 = external0.OplogMessageV0
316
+
317
+ const encoding13 = external0.OplogMessageV1
318
+
319
+ // @autobase-compat/oplog-message-v2.checkpoint
320
+ const encoding14_1 = c.frame(encoding7)
321
+ // @autobase-compat/oplog-message-v2.digest
322
+ const encoding14_2 = c.frame(encoding8)
323
+ // @autobase-compat/oplog-message-v2.trace
324
+ const encoding14_4 = c.frame(encoding11)
325
+
326
+ // @autobase-compat/oplog-message-v2
327
+ const encoding14 = {
328
+ preencode(state, m) {
329
+ encoding9.preencode(state, m.node)
330
+ state.end++ // max flag is 8 so always one byte
331
+
332
+ if (m.checkpoint) encoding14_1.preencode(state, m.checkpoint)
333
+ if (m.digest) encoding14_2.preencode(state, m.digest)
334
+ if (m.trace) encoding14_4.preencode(state, m.trace)
335
+ },
336
+ encode(state, m) {
337
+ const flags =
338
+ (m.checkpoint ? 1 : 0) | (m.digest ? 2 : 0) | (m.optimistic ? 4 : 0) | (m.trace ? 8 : 0)
339
+
340
+ encoding9.encode(state, m.node)
341
+ c.uint.encode(state, flags)
342
+
343
+ if (m.checkpoint) encoding14_1.encode(state, m.checkpoint)
344
+ if (m.digest) encoding14_2.encode(state, m.digest)
345
+ if (m.trace) encoding14_4.encode(state, m.trace)
346
+ },
347
+ decode(state) {
348
+ const v = c.uint.decode(state)
349
+ const r0 = encoding9.decode(state)
350
+ const flags = c.uint.decode(state)
351
+
352
+ return {
353
+ version: v,
354
+ node: r0,
355
+ checkpoint: (flags & 1) !== 0 ? encoding14_1.decode(state) : null,
356
+ digest: (flags & 2) !== 0 ? encoding14_2.decode(state) : null,
357
+ optimistic: (flags & 4) !== 0,
358
+ trace: (flags & 8) !== 0 ? encoding14_4.decode(state) : null
359
+ }
360
+ }
361
+ }
362
+
363
+ // @autobase-compat/info-v1.pendingIndexers
364
+ const encoding15_1 = c.array(c.fixed32)
365
+
366
+ // @autobase-compat/info-v1
367
+ const encoding15 = {
368
+ preencode(state, m) {
369
+ c.uint.preencode(state, m.members)
370
+ encoding15_1.preencode(state, m.pendingIndexers)
371
+ encoding1.preencode(state, m.indexers)
372
+ encoding1.preencode(state, m.heads)
373
+ encoding1.preencode(state, m.views)
374
+ },
375
+ encode(state, m) {
376
+ c.uint.encode(state, m.members)
377
+ encoding15_1.encode(state, m.pendingIndexers)
378
+ encoding1.encode(state, m.indexers)
379
+ encoding1.encode(state, m.heads)
380
+ encoding1.encode(state, m.views)
381
+ },
382
+ decode(state) {
383
+ const v = c.uint.decode(state)
384
+ const r0 = c.uint.decode(state)
385
+ const r1 = encoding15_1.decode(state)
386
+ const r2 = encoding1.decode(state)
387
+ const r3 = encoding1.decode(state)
388
+ const r4 = encoding1.decode(state)
389
+
390
+ return {
391
+ version: v,
392
+ members: r0,
393
+ pendingIndexers: r1,
394
+ indexers: r2,
395
+ heads: r3,
396
+ views: r4
397
+ }
398
+ }
399
+ }
400
+
401
+ // @autobase-compat/info-v2.pendingIndexers
402
+ const encoding16_1 = encoding15_1
403
+
404
+ // @autobase-compat/info-v2
405
+ const encoding16 = {
406
+ preencode(state, m) {
407
+ c.uint.preencode(state, m.members)
408
+ encoding16_1.preencode(state, m.pendingIndexers)
409
+ encoding1.preencode(state, m.indexers)
410
+ encoding1.preencode(state, m.heads)
411
+ encoding1.preencode(state, m.views)
412
+ c.uint.preencode(state, m.encryptionLength)
413
+ state.end++ // max flag is 1 so always one byte
414
+
415
+ if (m.entropy) c.fixed32.preencode(state, m.entropy)
416
+ },
417
+ encode(state, m) {
418
+ const flags = m.entropy ? 1 : 0
419
+
420
+ c.uint.encode(state, m.members)
421
+ encoding16_1.encode(state, m.pendingIndexers)
422
+ encoding1.encode(state, m.indexers)
423
+ encoding1.encode(state, m.heads)
424
+ encoding1.encode(state, m.views)
425
+ c.uint.encode(state, m.encryptionLength)
426
+ c.uint.encode(state, flags)
427
+
428
+ if (m.entropy) c.fixed32.encode(state, m.entropy)
429
+ },
430
+ decode(state) {
431
+ const v = c.uint.decode(state)
432
+ const r0 = c.uint.decode(state)
433
+ const r1 = encoding16_1.decode(state)
434
+ const r2 = encoding1.decode(state)
435
+ const r3 = encoding1.decode(state)
436
+ const r4 = encoding1.decode(state)
437
+ const r5 = c.uint.decode(state)
438
+ const flags = c.uint.decode(state)
439
+
440
+ return {
441
+ version: v,
442
+ members: r0,
443
+ pendingIndexers: r1,
444
+ indexers: r2,
445
+ heads: r3,
446
+ views: r4,
447
+ encryptionLength: r5,
448
+ entropy: (flags & 1) !== 0 ? c.fixed32.decode(state) : null
449
+ }
450
+ }
451
+ }
452
+
453
+ const encoding17 = external0.SystemWriterV0
454
+
455
+ // @autobee/system-info-v3
456
+ const encoding18 = {
457
+ preencode(state, m) {
458
+ c.uint.preencode(state, m.timestamp)
459
+ c.uint.preencode(state, m.flushes)
460
+ encoding22.preencode(state, m.view)
461
+ encoding18_3.preencode(state, m.heads)
462
+ state.end++ // max flag is 1 so always one byte
463
+
464
+ if (m.indexers) encoding18_4.preencode(state, m.indexers)
465
+ },
466
+ encode(state, m) {
467
+ const flags = m.indexers ? 1 : 0
468
+
469
+ c.uint.encode(state, m.timestamp)
470
+ c.uint.encode(state, m.flushes)
471
+ encoding22.encode(state, m.view)
472
+ encoding18_3.encode(state, m.heads)
473
+ c.uint.encode(state, flags)
474
+
475
+ if (m.indexers) encoding18_4.encode(state, m.indexers)
476
+ },
477
+ decode(state) {
478
+ const v = c.uint.decode(state)
479
+ const r0 = c.uint.decode(state)
480
+ const r1 = c.uint.decode(state)
481
+ const r2 = encoding22.decode(state)
482
+ const r3 = encoding18_3.decode(state)
483
+ const flags = c.uint.decode(state)
484
+
485
+ return {
486
+ version: v,
487
+ timestamp: r0,
488
+ flushes: r1,
489
+ view: r2,
490
+ heads: r3,
491
+ indexers: (flags & 1) !== 0 ? encoding18_4.decode(state) : null
492
+ }
493
+ }
494
+ }
495
+
496
+ // @autobee/system-info
497
+ const encoding19 = {
498
+ preencode(state, m) {
499
+ c.uint.preencode(state, m.version)
500
+ switch (m.version) {
501
+ case 0:
502
+ case 1:
503
+ encoding15.preencode(state, m)
504
+ break
505
+ case 2:
506
+ encoding16.preencode(state, m)
507
+ break
508
+ case 3:
509
+ encoding18.preencode(state, m)
510
+ break
511
+ default:
512
+ throw new Error('Unsupported version')
513
+ }
514
+ },
515
+ encode(state, m) {
516
+ c.uint.encode(state, m.version)
517
+ switch (m.version) {
518
+ case 0:
519
+ case 1:
520
+ encoding15.encode(state, m)
521
+ break
522
+ case 2:
523
+ encoding16.encode(state, m)
524
+ break
525
+ case 3:
526
+ encoding18.encode(state, m)
527
+ break
528
+ default:
529
+ throw new Error('Unsupported version')
530
+ }
531
+ },
532
+ decode(state) {
533
+ const start = state.start
534
+ const v = c.uint.decode(state)
535
+ state.start = start
536
+ switch (v) {
537
+ case 0:
538
+ case 1: {
539
+ const decoded = encoding15.decode(state)
540
+ const map = external0.infoLegacyMap
541
+ return map(decoded)
542
+ }
543
+ case 2: {
544
+ const decoded = encoding16.decode(state)
545
+ return decoded
546
+ }
547
+ case 3: {
548
+ const decoded = encoding18.decode(state)
549
+ return decoded
550
+ }
551
+ default:
552
+ throw new Error('Unsupported version')
553
+ }
554
+ }
555
+ }
556
+
557
+ // @autobee/system-writer-v4
558
+ const encoding20 = {
559
+ preencode(state, m) {
560
+ state.end++ // max flag is 2 so always one byte
561
+ c.uint.preencode(state, m.weight)
562
+ c.uint.preencode(state, m.length)
563
+ c.uint.preencode(state, m.clock)
564
+ },
565
+ encode(state, m) {
566
+ const flags = (m.isRemoved ? 1 : 0) | (m.isOplog ? 2 : 0)
567
+
568
+ c.uint.encode(state, flags)
569
+ c.uint.encode(state, m.weight)
570
+ c.uint.encode(state, m.length)
571
+ c.uint.encode(state, m.clock)
572
+ },
573
+ decode(state) {
574
+ const v = c.uint.decode(state)
575
+ const flags = c.uint.decode(state)
576
+
577
+ return {
578
+ version: v,
579
+ isRemoved: (flags & 1) !== 0,
580
+ isOplog: (flags & 2) !== 0,
581
+ weight: c.uint.decode(state),
582
+ length: c.uint.decode(state),
583
+ clock: c.uint.decode(state)
584
+ }
585
+ }
586
+ }
587
+
588
+ // @autobee/system-writer
589
+ const encoding21 = {
590
+ preencode(state, m) {
591
+ c.uint.preencode(state, m.version)
592
+ switch (m.version) {
593
+ case 0:
594
+ case 1:
595
+ case 2:
596
+ case 3:
597
+ encoding17.preencode(state, m)
598
+ break
599
+ case 4:
600
+ encoding20.preencode(state, m)
601
+ break
602
+ default:
603
+ throw new Error('Unsupported version')
604
+ }
605
+ },
606
+ encode(state, m) {
607
+ c.uint.encode(state, m.version)
608
+ switch (m.version) {
609
+ case 0:
610
+ case 1:
611
+ case 2:
612
+ case 3:
613
+ encoding17.encode(state, m)
614
+ break
615
+ case 4:
616
+ encoding20.encode(state, m)
617
+ break
618
+ default:
619
+ throw new Error('Unsupported version')
620
+ }
621
+ },
622
+ decode(state) {
623
+ const start = state.start
624
+ const v = c.uint.decode(state)
625
+ state.start = start
626
+ switch (v) {
627
+ case 0:
628
+ case 1:
629
+ case 2:
630
+ case 3: {
631
+ const decoded = encoding17.decode(state)
632
+ const map = external0.memberLegacyMap
633
+ return map(decoded)
634
+ }
635
+ case 4: {
636
+ const decoded = encoding20.decode(state)
637
+ return decoded
638
+ }
639
+ default:
640
+ throw new Error('Unsupported version')
641
+ }
642
+ }
643
+ }
644
+
645
+ // @autobee/link
646
+ const encoding22 = encoding0
647
+
648
+ // @autobee/batch
649
+ const encoding23 = {
650
+ preencode(state, m) {
651
+ c.uint.preencode(state, m.start)
652
+ c.uint.preencode(state, m.end)
653
+ },
654
+ encode(state, m) {
655
+ c.uint.encode(state, m.start)
656
+ c.uint.encode(state, m.end)
657
+ },
658
+ decode(state) {
659
+ const r0 = c.uint.decode(state)
660
+ const r1 = c.uint.decode(state)
661
+
662
+ return {
663
+ start: r0,
664
+ end: r1
665
+ }
666
+ }
667
+ }
668
+
669
+ // @autobee/views
670
+ const encoding24 = {
671
+ preencode(state, m) {
672
+ encoding22.preencode(state, m.system)
673
+ c.uint.preencode(state, m.flushes)
674
+ state.end++ // flags are fixed size
675
+
676
+ if (m.view) encoding22.preencode(state, m.view)
677
+ },
678
+ encode(state, m) {
679
+ const flags = m.view ? 1 : 0
680
+
681
+ encoding22.encode(state, m.system)
682
+ c.uint.encode(state, m.flushes)
683
+ c.uint8.encode(state, flags)
684
+
685
+ if (m.view) encoding22.encode(state, m.view)
686
+ },
687
+ decode(state) {
688
+ const r0 = encoding22.decode(state)
689
+ const r1 = c.uint.decode(state)
690
+ const flags = c.uint8.decode(state)
691
+
692
+ return {
693
+ system: r0,
694
+ flushes: r1,
695
+ view: (flags & 1) !== 0 ? encoding22.decode(state) : null
696
+ }
697
+ }
698
+ }
699
+
700
+ // @autobee/views (inline)
701
+ const encoding24_inline = {
702
+ preencode(state, m) {
703
+ encoding22.preencode(state, m.system)
704
+ c.uint.preencode(state, m.flushes)
705
+
706
+ if (m.view) encoding22.preencode(state, m.view)
707
+ },
708
+ encode(state, m) {
709
+ encoding22.encode(state, m.system)
710
+ c.uint.encode(state, m.flushes)
711
+
712
+ if (m.view) encoding22.encode(state, m.view)
713
+ },
714
+ decode(state, inlining) {
715
+ const r0 = encoding22.decode(state)
716
+ const r1 = c.uint.decode(state)
717
+ const flags = inlining
718
+
719
+ return {
720
+ system: r0,
721
+ flushes: r1,
722
+ view: (flags & 1) !== 0 ? encoding22.decode(state) : null
723
+ }
724
+ }
725
+ }
726
+
727
+ // @autobee/oplog-message-v3
728
+ const encoding25 = {
729
+ preencode(state, m) {
730
+ c.uint.preencode(state, m.timestamp)
731
+ encoding25_1.preencode(state, m.links)
732
+ state.end++ // max flag is 16 so always one byte
733
+
734
+ if (m.batch) encoding23.preencode(state, m.batch)
735
+ if (m.views) encoding24_inline.preencode(state, m.views)
736
+ if (m.value) c.buffer.preencode(state, m.value)
737
+ },
738
+ encode(state, m) {
739
+ let flags = (m.batch ? 1 : 0) | (m.views ? 2 : 0) | (m.optimistic ? 8 : 0) | (m.value ? 16 : 0)
740
+ if (m.views) {
741
+ flags |= m.views.view ? 4 : 0
742
+ }
743
+
744
+ c.uint.encode(state, m.timestamp)
745
+ encoding25_1.encode(state, m.links)
746
+ c.uint.encode(state, flags)
747
+
748
+ if (m.batch) encoding23.encode(state, m.batch)
749
+ if (m.views) encoding24_inline.encode(state, m.views)
750
+ if (m.value) c.buffer.encode(state, m.value)
751
+ },
752
+ decode(state) {
753
+ const v = c.uint.decode(state)
754
+ const r0 = c.uint.decode(state)
755
+ const r1 = encoding25_1.decode(state)
756
+ const flags = c.uint.decode(state)
757
+
758
+ return {
759
+ version: v,
760
+ timestamp: r0,
761
+ links: r1,
762
+ batch: (flags & 1) !== 0 ? encoding23.decode(state) : null,
763
+ views: (flags & 2) !== 0 ? encoding24_inline.decode(state, flags >>> 2) : null,
764
+ optimistic: (flags & 8) !== 0,
765
+ value: (flags & 16) !== 0 ? c.buffer.decode(state) : null
766
+ }
767
+ }
768
+ }
769
+
770
+ // @autobee/oplog
771
+ const encoding26 = {
772
+ preencode(state, m) {
773
+ c.uint.preencode(state, m.version)
774
+ switch (m.version) {
775
+ case 0:
776
+ encoding12.preencode(state, m)
777
+ break
778
+ case 1:
779
+ encoding13.preencode(state, m)
780
+ break
781
+ case 2:
782
+ encoding14.preencode(state, m)
783
+ break
784
+ case 3:
785
+ encoding25.preencode(state, m)
786
+ break
787
+ default:
788
+ throw new Error('Unsupported version')
789
+ }
790
+ },
791
+ encode(state, m) {
792
+ c.uint.encode(state, m.version)
793
+ switch (m.version) {
794
+ case 0:
795
+ encoding12.encode(state, m)
796
+ break
797
+ case 1:
798
+ encoding13.encode(state, m)
799
+ break
800
+ case 2:
801
+ encoding14.encode(state, m)
802
+ break
803
+ case 3:
804
+ encoding25.encode(state, m)
805
+ break
806
+ default:
807
+ throw new Error('Unsupported version')
808
+ }
809
+ },
810
+ decode(state) {
811
+ const start = state.start
812
+ const v = c.uint.decode(state)
813
+ state.start = start
814
+ switch (v) {
815
+ case 0: {
816
+ const decoded = encoding12.decode(state)
817
+ return decoded
818
+ }
819
+ case 1: {
820
+ const decoded = encoding13.decode(state)
821
+ return decoded
822
+ }
823
+ case 2: {
824
+ const decoded = encoding14.decode(state)
825
+ return decoded
826
+ }
827
+ case 3: {
828
+ const decoded = encoding25.decode(state)
829
+ return decoded
830
+ }
831
+ default:
832
+ throw new Error('Unsupported version')
833
+ }
834
+ }
835
+ }
836
+
837
+ // @autobee/manifest-data
838
+ const encoding27 = {
839
+ preencode(state, m) {
840
+ c.uint.preencode(state, m.version)
841
+ state.end++ // max flag is 2 so always one byte
842
+
843
+ if (m.legacyBlocks) c.uint.preencode(state, m.legacyBlocks)
844
+ if (m.namespace) c.fixed32.preencode(state, m.namespace)
845
+ },
846
+ encode(state, m) {
847
+ const flags = (m.legacyBlocks ? 1 : 0) | (m.namespace ? 2 : 0)
848
+
849
+ c.uint.encode(state, m.version)
850
+ c.uint.encode(state, flags)
851
+
852
+ if (m.legacyBlocks) c.uint.encode(state, m.legacyBlocks)
853
+ if (m.namespace) c.fixed32.encode(state, m.namespace)
854
+ },
855
+ decode(state) {
856
+ const r0 = c.uint.decode(state)
857
+ const flags = c.uint.decode(state)
858
+
859
+ return {
860
+ version: r0,
861
+ legacyBlocks: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
862
+ namespace: (flags & 2) !== 0 ? c.fixed32.decode(state) : null
863
+ }
864
+ }
865
+ }
866
+
867
+ // @autobee/system-info-v3.heads, deferred due to recusive use
868
+ const encoding18_3 = c.array(encoding22)
869
+ // @autobee/system-info-v3.indexers, deferred due to recusive use
870
+ const encoding18_4 = encoding18_3
871
+ // @autobee/oplog-message-v3.links, deferred due to recusive use
872
+ const encoding25_1 = encoding18_3
873
+
874
+ function setVersion(v) {
875
+ version = v
876
+ }
877
+
878
+ function encode(name, value, v = VERSION) {
879
+ version = v
880
+ return c.encode(getEncoding(name), value)
881
+ }
882
+
883
+ function decode(name, buffer, v = VERSION) {
884
+ version = v
885
+ return c.decode(getEncoding(name), buffer)
886
+ }
887
+
888
+ function getEnum(name) {
889
+ switch (name) {
890
+ default:
891
+ throw new Error('Enum not found ' + name)
892
+ }
893
+ }
894
+
895
+ function getEncoding(name) {
896
+ switch (name) {
897
+ case '@autobase-compat/checkout':
898
+ return encoding0
899
+ case '@autobase-compat/clock':
900
+ return encoding1
901
+ case '@autobase-compat/index-checkpoint':
902
+ return encoding2
903
+ case '@autobase-compat/boot-record-v0':
904
+ return encoding3
905
+ case '@autobase-compat/boot-record-raw':
906
+ return encoding4
907
+ case '@autobase-compat/boot-record':
908
+ return encoding5
909
+ case '@autobase-compat/checkpointer':
910
+ return encoding6
911
+ case '@autobase-compat/checkpoint':
912
+ return encoding7
913
+ case '@autobase-compat/digest':
914
+ return encoding8
915
+ case '@autobase-compat/node':
916
+ return encoding9
917
+ case '@autobase-compat/user-view-trace':
918
+ return encoding10
919
+ case '@autobase-compat/trace':
920
+ return encoding11
921
+ case '@autobase-compat/oplog-message-v0':
922
+ return encoding12
923
+ case '@autobase-compat/oplog-message-v1':
924
+ return encoding13
925
+ case '@autobase-compat/oplog-message-v2':
926
+ return encoding14
927
+ case '@autobase-compat/info-v1':
928
+ return encoding15
929
+ case '@autobase-compat/info-v2':
930
+ return encoding16
931
+ case '@autobase-compat/member':
932
+ return encoding17
933
+ case '@autobee/system-info-v3':
934
+ return encoding18
935
+ case '@autobee/system-info':
936
+ return encoding19
937
+ case '@autobee/system-writer-v4':
938
+ return encoding20
939
+ case '@autobee/system-writer':
940
+ return encoding21
941
+ case '@autobee/link':
942
+ return encoding22
943
+ case '@autobee/batch':
944
+ return encoding23
945
+ case '@autobee/views':
946
+ return encoding24
947
+ case '@autobee/oplog-message-v3':
948
+ return encoding25
949
+ case '@autobee/oplog':
950
+ return encoding26
951
+ case '@autobee/manifest-data':
952
+ return encoding27
953
+ default:
954
+ throw new Error('Encoder not found ' + name)
955
+ }
956
+ }
957
+
958
+ function getStruct(name, v = VERSION) {
959
+ const enc = getEncoding(name)
960
+ return {
961
+ preencode(state, m) {
962
+ version = v
963
+ enc.preencode(state, m)
964
+ },
965
+ encode(state, m) {
966
+ version = v
967
+ enc.encode(state, m)
968
+ },
969
+ decode(state) {
970
+ version = v
971
+ return enc.decode(state)
972
+ }
973
+ }
974
+ }
975
+
976
+ const resolveStruct = getStruct // compat
977
+
978
+ module.exports = {
979
+ resolveStruct,
980
+ getStruct,
981
+ getEnum,
982
+ getEncoding,
983
+ encode,
984
+ decode,
985
+ setVersion,
986
+ version
987
+ }