-
Notifications
You must be signed in to change notification settings - Fork 8
/
codec.go
851 lines (785 loc) · 24.3 KB
/
codec.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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
// ssz: Go Simple Serialize (SSZ) codec library
// Copyright 2024 ssz Authors
// SPDX-License-Identifier: BSD-3-Clause
package ssz
import (
"math/big"
"github.com/holiman/uint256"
"github.com/prysmaticlabs/go-bitfield"
)
// Codec is a unified SSZ encoder and decoder that allows simple structs to
// define their schemas once and have that work for both operations at once
// (with the same speed as explicitly typing them out would, of course).
type Codec struct {
fork Fork // Context for cross-fork monolith types
enc *Encoder
dec *Decoder
has *Hasher
}
// DefineEncoder uses a dedicated encoder in case the types SSZ conversion is for
// some reason asymmetric (e.g. encoding depends on fields, decoding depends on
// outer context).
//
// In reality, it will be the live code run when the object is being serialized.
func (c *Codec) DefineEncoder(impl func(enc *Encoder)) {
if c.enc != nil {
impl(c.enc)
}
}
// DefineDecoder uses a dedicated decoder in case the types SSZ conversion is for
// some reason asymmetric (e.g. encoding depends on fields, decoding depends on
// outer context).
//
// In reality, it will be the live code run when the object is being parsed.
func (c *Codec) DefineDecoder(impl func(dec *Decoder)) {
if c.dec != nil {
impl(c.dec)
}
}
// DefineHasher uses a dedicated hasher in case the types SSZ conversion is for
// some reason asymmetric (e.g. encoding depends on fields, decoding depends on
// outer context).
//
// In reality, it will be the live code run when the object is being parsed.
func (c *Codec) DefineHasher(impl func(has *Hasher)) {
if c.has != nil {
impl(c.has)
}
}
// DefineBool defines the next field as a 1 byte boolean.
func DefineBool[T ~bool](c *Codec, v *T) {
if c.enc != nil {
EncodeBool(c.enc, *v)
return
}
if c.dec != nil {
DecodeBool(c.dec, v)
return
}
HashBool(c.has, *v)
}
// DefineBoolPointerOnFork defines the next field as a 1 byte boolean if present
// in a fork.
func DefineBoolPointerOnFork[T ~bool](c *Codec, v **T, filter ForkFilter) {
if c.enc != nil {
EncodeBoolPointerOnFork(c.enc, *v, filter)
return
}
if c.dec != nil {
DecodeBoolPointerOnFork(c.dec, v, filter)
return
}
HashBoolPointerOnFork(c.has, *v, filter)
}
// DefineUint8 defines the next field as a uint8.
func DefineUint8[T ~uint8](c *Codec, n *T) {
if c.enc != nil {
EncodeUint8(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint8(c.dec, n)
return
}
HashUint8(c.has, *n)
}
// DefineUint8PointerOnFork defines the next field as a uint8 if present in a fork.
func DefineUint8PointerOnFork[T ~uint8](c *Codec, n **T, filter ForkFilter) {
if c.enc != nil {
EncodeUint8PointerOnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint8PointerOnFork(c.dec, n, filter)
return
}
HashUint8PointerOnFork(c.has, *n, filter)
}
// DefineUint16 defines the next field as a uint16.
func DefineUint16[T ~uint16](c *Codec, n *T) {
if c.enc != nil {
EncodeUint16(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint16(c.dec, n)
return
}
HashUint16(c.has, *n)
}
// DefineUint16PointerOnFork defines the next field as a uint16 if present in a fork.
func DefineUint16PointerOnFork[T ~uint16](c *Codec, n **T, filter ForkFilter) {
if c.enc != nil {
EncodeUint16PointerOnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint16PointerOnFork(c.dec, n, filter)
return
}
HashUint16PointerOnFork(c.has, *n, filter)
}
// DefineUint32 defines the next field as a uint32.
func DefineUint32[T ~uint32](c *Codec, n *T) {
if c.enc != nil {
EncodeUint32(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint32(c.dec, n)
return
}
HashUint32(c.has, *n)
}
// DefineUint32PointerOnFork defines the next field as a uint32 if present in a fork.
func DefineUint32PointerOnFork[T ~uint32](c *Codec, n **T, filter ForkFilter) {
if c.enc != nil {
EncodeUint32PointerOnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint32PointerOnFork(c.dec, n, filter)
return
}
HashUint32PointerOnFork(c.has, *n, filter)
}
// DefineUint64 defines the next field as a uint64.
func DefineUint64[T ~uint64](c *Codec, n *T) {
if c.enc != nil {
EncodeUint64(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint64(c.dec, n)
return
}
HashUint64(c.has, *n)
}
// DefineUint64PointerOnFork defines the next field as a uint64 if present in a fork.
func DefineUint64PointerOnFork[T ~uint64](c *Codec, n **T, filter ForkFilter) {
if c.enc != nil {
EncodeUint64PointerOnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint64PointerOnFork(c.dec, n, filter)
return
}
HashUint64PointerOnFork(c.has, *n, filter)
}
// DefineUint256 defines the next field as a uint256.
func DefineUint256(c *Codec, n **uint256.Int) {
if c.enc != nil {
EncodeUint256(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint256(c.dec, n)
return
}
HashUint256(c.has, *n)
}
// DefineUint256OnFork defines the next field as a uint256 if present in a fork.
func DefineUint256OnFork(c *Codec, n **uint256.Int, filter ForkFilter) {
if c.enc != nil {
EncodeUint256OnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint256OnFork(c.dec, n, filter)
return
}
HashUint256OnFork(c.has, *n, filter)
}
// DefineUint256BigInt defines the next field as a uint256.
func DefineUint256BigInt(c *Codec, n **big.Int) {
if c.enc != nil {
EncodeUint256BigInt(c.enc, *n)
return
}
if c.dec != nil {
DecodeUint256BigInt(c.dec, n)
return
}
HashUint256BigInt(c.has, *n)
}
// DefineUint256BigIntOnFork defines the next field as a uint256 if present in a
// fork.
func DefineUint256BigIntOnFork(c *Codec, n **big.Int, filter ForkFilter) {
if c.enc != nil {
EncodeUint256BigIntOnFork(c.enc, *n, filter)
return
}
if c.dec != nil {
DecodeUint256BigIntOnFork(c.dec, n, filter)
return
}
HashUint256BigIntOnFork(c.has, *n, filter)
}
// DefineStaticBytes defines the next field as static binary blob. This method
// can be used for byte arrays.
func DefineStaticBytes[T commonBytesLengths](c *Codec, blob *T) {
if c.enc != nil {
EncodeStaticBytes(c.enc, blob)
return
}
if c.dec != nil {
DecodeStaticBytes(c.dec, blob)
return
}
HashStaticBytes(c.has, blob)
}
// DefineStaticBytesPointerOnFork defines the next field as static binary blob if present
// in a fork. This method can be used for byte arrays.
func DefineStaticBytesPointerOnFork[T commonBytesLengths](c *Codec, blob **T, filter ForkFilter) {
if c.enc != nil {
EncodeStaticBytesPointerOnFork(c.enc, *blob, filter)
return
}
if c.dec != nil {
DecodeStaticBytesPointerOnFork(c.dec, blob, filter)
return
}
HashStaticBytesPointerOnFork(c.has, *blob, filter)
}
// DefineCheckedStaticBytes defines the next field as static binary blob. This
// method can be used for plain byte slices, which is more expensive, since it
// needs runtime size validation.
func DefineCheckedStaticBytes(c *Codec, blob *[]byte, size uint64) {
if c.enc != nil {
EncodeCheckedStaticBytes(c.enc, *blob, size)
return
}
if c.dec != nil {
DecodeCheckedStaticBytes(c.dec, blob, size)
return
}
HashCheckedStaticBytes(c.has, *blob)
}
// DefineDynamicBytesOffset defines the next field as dynamic binary blob.
func DefineDynamicBytesOffset(c *Codec, blob *[]byte, maxSize uint64) {
if c.enc != nil {
EncodeDynamicBytesOffset(c.enc, *blob)
return
}
if c.dec != nil {
DecodeDynamicBytesOffset(c.dec, blob)
return
}
HashDynamicBytes(c.has, *blob, maxSize)
}
// DefineDynamicBytesOffsetOnFork defines the next field as dynamic binary blob
// if present in a fork.
func DefineDynamicBytesOffsetOnFork(c *Codec, blob *[]byte, maxSize uint64, filter ForkFilter) {
if c.enc != nil {
EncodeDynamicBytesOffsetOnFork(c.enc, *blob, filter)
return
}
if c.dec != nil {
DecodeDynamicBytesOffsetOnFork(c.dec, blob, filter)
return
}
HashDynamicBytesOnFork(c.has, *blob, maxSize, filter)
}
// DefineDynamicBytesContent defines the next field as dynamic binary blob.
func DefineDynamicBytesContent(c *Codec, blob *[]byte, maxSize uint64) {
if c.enc != nil {
EncodeDynamicBytesContent(c.enc, *blob)
return
}
if c.dec != nil {
DecodeDynamicBytesContent(c.dec, blob, maxSize)
return
}
// No hashing, done at the offset position
}
// DefineDynamicBytesContentOnFork defines the next field as dynamic binary blob
// if present in a fork.
func DefineDynamicBytesContentOnFork(c *Codec, blob *[]byte, maxSize uint64, filter ForkFilter) {
if c.enc != nil {
EncodeDynamicBytesContentOnFork(c.enc, *blob, filter)
return
}
if c.dec != nil {
DecodeDynamicBytesContentOnFork(c.dec, blob, maxSize, filter)
return
}
// No hashing, done at the offset position
}
// DefineStaticObject defines the next field as a static ssz object.
func DefineStaticObject[T newableStaticObject[U], U any](c *Codec, obj *T) {
if c.enc != nil {
EncodeStaticObject(c.enc, *obj)
return
}
if c.dec != nil {
DecodeStaticObject(c.dec, obj)
return
}
HashStaticObject(c.has, *obj)
}
// DefineStaticObjectOnFork defines the next field as a static ssz object if
// present in a fork.
func DefineStaticObjectOnFork[T newableStaticObject[U], U any](c *Codec, obj *T, filter ForkFilter) {
if c.enc != nil {
EncodeStaticObjectOnFork(c.enc, *obj, filter)
return
}
if c.dec != nil {
DecodeStaticObjectOnFork(c.dec, obj, filter)
return
}
HashStaticObjectOnFork(c.has, *obj, filter)
}
// DefineDynamicObjectOffset defines the next field as a dynamic ssz object.
func DefineDynamicObjectOffset[T newableDynamicObject[U], U any](c *Codec, obj *T) {
if c.enc != nil {
EncodeDynamicObjectOffset(c.enc, *obj)
return
}
if c.dec != nil {
DecodeDynamicObjectOffset(c.dec, obj)
return
}
HashDynamicObject(c.has, *obj)
}
// DefineDynamicObjectOffsetOnFork defines the next field as a dynamic ssz object
// if present in a fork.
func DefineDynamicObjectOffsetOnFork[T newableDynamicObject[U], U any](c *Codec, obj *T, filter ForkFilter) {
if c.enc != nil {
EncodeDynamicObjectOffsetOnFork(c.enc, *obj, filter)
return
}
if c.dec != nil {
DecodeDynamicObjectOffsetOnFork(c.dec, obj, filter)
return
}
HashDynamicObjectOnFork(c.has, *obj, filter)
}
// DefineDynamicObjectContent defines the next field as a dynamic ssz object.
func DefineDynamicObjectContent[T newableDynamicObject[U], U any](c *Codec, obj *T) {
if c.enc != nil {
EncodeDynamicObjectContent(c.enc, *obj)
return
}
if c.dec != nil {
DecodeDynamicObjectContent(c.dec, obj)
return
}
// No hashing, done at the offset position
}
// DefineDynamicObjectContentOnFork defines the next field as a dynamic ssz object
// if present in a fork.
func DefineDynamicObjectContentOnFork[T newableDynamicObject[U], U any](c *Codec, obj *T, filter ForkFilter) {
if c.enc != nil {
EncodeDynamicObjectContentOnFork(c.enc, *obj, filter)
return
}
if c.dec != nil {
DecodeDynamicObjectContentOnFork(c.dec, obj, filter)
return
}
// No hashing, done at the offset position
}
// DefineArrayOfBits defines the next field as a static array of (packed) bits.
func DefineArrayOfBits[T commonBitsLengths](c *Codec, bits *T, size uint64) {
if c.enc != nil {
EncodeArrayOfBits(c.enc, bits)
return
}
if c.dec != nil {
DecodeArrayOfBits(c.dec, bits, size)
return
}
HashArrayOfBits(c.has, bits)
}
// DefineArrayOfBitsPointerOnFork defines the next field as a static array of
// (packed) bits if present in a fork.
func DefineArrayOfBitsPointerOnFork[T commonBitsLengths](c *Codec, bits **T, size uint64, filter ForkFilter) {
if c.enc != nil {
EncodeArrayOfBitsPointerOnFork(c.enc, *bits, filter)
return
}
if c.dec != nil {
DecodeArrayOfBitsPointerOnFork(c.dec, bits, size, filter)
return
}
HashArrayOfBitsPointerOnFork(c.has, *bits, filter)
}
// DefineSliceOfBitsOffset defines the next field as a dynamic slice of (packed)
// bits.
func DefineSliceOfBitsOffset(c *Codec, bits *bitfield.Bitlist, maxBits uint64) {
if c.enc != nil {
EncodeSliceOfBitsOffset(c.enc, *bits)
return
}
if c.dec != nil {
DecodeSliceOfBitsOffset(c.dec, bits)
return
}
HashSliceOfBits(c.has, *bits, maxBits)
}
// DefineSliceOfBitsOffsetOnFork defines the next field as a dynamic slice of
// (packed) bits if present in a fork.
func DefineSliceOfBitsOffsetOnFork(c *Codec, bits *bitfield.Bitlist, maxBits uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfBitsOffsetOnFork(c.enc, *bits, filter)
return
}
if c.dec != nil {
DecodeSliceOfBitsOffsetOnFork(c.dec, bits, filter)
return
}
HashSliceOfBitsOnFork(c.has, *bits, maxBits, filter)
}
// DefineSliceOfBitsContent defines the next field as a dynamic slice of (packed)
// bits.
func DefineSliceOfBitsContent(c *Codec, bits *bitfield.Bitlist, maxBits uint64) {
if c.enc != nil {
EncodeSliceOfBitsContent(c.enc, *bits)
return
}
if c.dec != nil {
DecodeSliceOfBitsContent(c.dec, bits, maxBits)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfBitsContentOnFork defines the next field as a dynamic slice of
// (packed) bits if present in a fork.
func DefineSliceOfBitsContentOnFork(c *Codec, bits *bitfield.Bitlist, maxBits uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfBitsContentOnFork(c.enc, *bits, filter)
return
}
if c.dec != nil {
DecodeSliceOfBitsContentOnFork(c.dec, bits, maxBits, filter)
return
}
// No hashing, done at the offset position
}
// DefineArrayOfUint64s defines the next field as a static array of uint64s.
func DefineArrayOfUint64s[T commonUint64sLengths](c *Codec, ns *T) {
if c.enc != nil {
EncodeArrayOfUint64s(c.enc, ns)
return
}
if c.dec != nil {
DecodeArrayOfUint64s(c.dec, ns)
return
}
HashArrayOfUint64s(c.has, ns)
}
// DefineArrayOfUint64sPointerOnFork defines the next field as a static array of
// uint64s if present in a fork.
func DefineArrayOfUint64sPointerOnFork[T commonUint64sLengths](c *Codec, ns **T, filter ForkFilter) {
if c.enc != nil {
EncodeArrayOfUint64sPointerOnFork(c.enc, *ns, filter)
return
}
if c.dec != nil {
DecodeArrayOfUint64sPointerOnFork(c.dec, ns, filter)
return
}
HashArrayOfUint64sPointerOnFork(c.has, *ns, filter)
}
// DefineSliceOfUint64sOffset defines the next field as a dynamic slice of uint64s.
func DefineSliceOfUint64sOffset[T ~uint64](c *Codec, ns *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfUint64sOffset(c.enc, *ns)
return
}
if c.dec != nil {
DecodeSliceOfUint64sOffset(c.dec, ns)
return
}
HashSliceOfUint64s(c.has, *ns, maxItems)
}
// DefineSliceOfUint64sOffsetOnFork defines the next field as a dynamic slice of
// uint64s if present in a fork.
func DefineSliceOfUint64sOffsetOnFork[T ~uint64](c *Codec, ns *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfUint64sOffsetOnFork(c.enc, *ns, filter)
return
}
if c.dec != nil {
DecodeSliceOfUint64sOffsetOnFork(c.dec, ns, filter)
return
}
HashSliceOfUint64sOnFork(c.has, *ns, maxItems, filter)
}
// DefineSliceOfUint64sContent defines the next field as a dynamic slice of uint64s.
func DefineSliceOfUint64sContent[T ~uint64](c *Codec, ns *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfUint64sContent(c.enc, *ns)
return
}
if c.dec != nil {
DecodeSliceOfUint64sContent(c.dec, ns, maxItems)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfUint64sContentOnFork defines the next field as a dynamic slice of
// uint64s if present in a fork.
func DefineSliceOfUint64sContentOnFork[T ~uint64](c *Codec, ns *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfUint64sContentOnFork(c.enc, *ns, filter)
return
}
if c.dec != nil {
DecodeSliceOfUint64sContentOnFork(c.dec, ns, maxItems, filter)
return
}
// No hashing, done at the offset position
}
// DefineArrayOfStaticBytes defines the next field as a static array of static
// binary blobs.
func DefineArrayOfStaticBytes[T commonBytesArrayLengths[U], U commonBytesLengths](c *Codec, blobs *T) {
if c.enc != nil {
EncodeArrayOfStaticBytes[T, U](c.enc, blobs)
return
}
if c.dec != nil {
DecodeArrayOfStaticBytes[T, U](c.dec, blobs)
return
}
HashArrayOfStaticBytes[T, U](c.has, blobs)
}
// DefineUnsafeArrayOfStaticBytes defines the next field as a static array of
// static binary blobs. This method operates on plain slices of byte arrays and
// will crash if provided a slice of a non-array. Its purpose is to get around
// Go's generics limitations in generated code (use DefineArrayOfStaticBytes).
func DefineUnsafeArrayOfStaticBytes[T commonBytesLengths](c *Codec, blobs []T) {
if c.enc != nil {
EncodeUnsafeArrayOfStaticBytes(c.enc, blobs)
return
}
if c.dec != nil {
DecodeUnsafeArrayOfStaticBytes(c.dec, blobs)
return
}
HashUnsafeArrayOfStaticBytes(c.has, blobs)
}
// DefineCheckedArrayOfStaticBytes defines the next field as a static array of
// static binary blobs. This method can be used for plain slices of byte arrays,
// which is more expensive since it needs runtime size validation.
func DefineCheckedArrayOfStaticBytes[T commonBytesLengths](c *Codec, blobs *[]T, size uint64) {
if c.enc != nil {
EncodeCheckedArrayOfStaticBytes(c.enc, *blobs, size)
return
}
if c.dec != nil {
DecodeCheckedArrayOfStaticBytes(c.dec, blobs, size)
return
}
HashCheckedArrayOfStaticBytes(c.has, *blobs)
}
// DefineSliceOfStaticBytesOffset defines the next field as a dynamic slice of
// static binary blobs.
func DefineSliceOfStaticBytesOffset[T commonBytesLengths](c *Codec, bytes *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfStaticBytesOffset(c.enc, *bytes)
return
}
if c.dec != nil {
DecodeSliceOfStaticBytesOffset(c.dec, bytes)
return
}
HashSliceOfStaticBytes(c.has, *bytes, maxItems)
}
// DefineSliceOfStaticBytesOffsetOnFork defines the next field as a dynamic slice
// of static binary blobs if present in a fork.
func DefineSliceOfStaticBytesOffsetOnFork[T commonBytesLengths](c *Codec, bytes *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfStaticBytesOffsetOnFork(c.enc, *bytes, filter)
return
}
if c.dec != nil {
DecodeSliceOfStaticBytesOffsetOnFork(c.dec, bytes, filter)
return
}
HashSliceOfStaticBytesOnFork(c.has, *bytes, maxItems, filter)
}
// DefineSliceOfStaticBytesContent defines the next field as a dynamic slice of static
// binary blobs.
func DefineSliceOfStaticBytesContent[T commonBytesLengths](c *Codec, blobs *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfStaticBytesContent(c.enc, *blobs)
return
}
if c.dec != nil {
DecodeSliceOfStaticBytesContent(c.dec, blobs, maxItems)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfStaticBytesContentOnFork defines the next field as a dynamic slice
// of static binary blobs if present in a fork.
func DefineSliceOfStaticBytesContentOnFork[T commonBytesLengths](c *Codec, blobs *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfStaticBytesContentOnFork(c.enc, *blobs, filter)
return
}
if c.dec != nil {
DecodeSliceOfStaticBytesContentOnFork(c.dec, blobs, maxItems, filter)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfDynamicBytesOffset defines the next field as a dynamic slice of
// dynamic binary blobs.
func DefineSliceOfDynamicBytesOffset(c *Codec, blobs *[][]byte, maxItems uint64, maxSize uint64) {
if c.enc != nil {
EncodeSliceOfDynamicBytesOffset(c.enc, *blobs)
return
}
if c.dec != nil {
DecodeSliceOfDynamicBytesOffset(c.dec, blobs)
return
}
HashSliceOfDynamicBytes(c.has, *blobs, maxItems, maxSize)
}
// DefineSliceOfDynamicBytesOffsetOnFork defines the next field as a dynamic slice
// of dynamic binary blobs if present in a fork.
func DefineSliceOfDynamicBytesOffsetOnFork(c *Codec, blobs *[][]byte, maxItems uint64, maxSize uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfDynamicBytesOffsetOnFork(c.enc, *blobs, filter)
return
}
if c.dec != nil {
DecodeSliceOfDynamicBytesOffsetOnFork(c.dec, blobs, filter)
return
}
HashSliceOfDynamicBytesOnFork(c.has, *blobs, maxItems, maxSize, filter)
}
// DefineSliceOfDynamicBytesContent defines the next field as a dynamic slice of
// dynamic binary blobs.
func DefineSliceOfDynamicBytesContent(c *Codec, blobs *[][]byte, maxItems uint64, maxSize uint64) {
if c.enc != nil {
EncodeSliceOfDynamicBytesContent(c.enc, *blobs)
return
}
if c.dec != nil {
DecodeSliceOfDynamicBytesContent(c.dec, blobs, maxItems, maxSize)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfDynamicBytesContentOnFork defines the next field as a dynamic
// slice of dynamic binary blobs.
func DefineSliceOfDynamicBytesContentOnFork(c *Codec, blobs *[][]byte, maxItems uint64, maxSize uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfDynamicBytesContentOnFork(c.enc, *blobs, filter)
return
}
if c.dec != nil {
DecodeSliceOfDynamicBytesContentOnFork(c.dec, blobs, maxItems, maxSize, filter)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfStaticObjectsOffset defines the next field as a dynamic slice of
// static ssz objects.
func DefineSliceOfStaticObjectsOffset[T newableStaticObject[U], U any](c *Codec, objects *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfStaticObjectsOffset(c.enc, *objects)
return
}
if c.dec != nil {
DecodeSliceOfStaticObjectsOffset(c.dec, objects)
return
}
HashSliceOfStaticObjects(c.has, *objects, maxItems)
}
// DefineSliceOfStaticObjectsOffsetOnFork defines the next field as a dynamic
// slice of static ssz objects if present in a fork.
func DefineSliceOfStaticObjectsOffsetOnFork[T newableStaticObject[U], U any](c *Codec, objects *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfStaticObjectsOffsetOnFork(c.enc, *objects, filter)
return
}
if c.dec != nil {
DecodeSliceOfStaticObjectsOffsetOnFork(c.dec, objects, filter)
return
}
HashSliceOfStaticObjectsOnFork(c.has, *objects, maxItems, filter)
}
// DefineSliceOfStaticObjectsContent defines the next field as a dynamic slice of static
// ssz objects.
func DefineSliceOfStaticObjectsContent[T newableStaticObject[U], U any](c *Codec, objects *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfStaticObjectsContent(c.enc, *objects)
return
}
if c.dec != nil {
DecodeSliceOfStaticObjectsContent(c.dec, objects, maxItems)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfStaticObjectsContentOnFork defines the next field as a dynamic
// slice of static ssz objects if present in a fork.
func DefineSliceOfStaticObjectsContentOnFork[T newableStaticObject[U], U any](c *Codec, objects *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfStaticObjectsContentOnFork(c.enc, *objects, filter)
return
}
if c.dec != nil {
DecodeSliceOfStaticObjectsContentOnFork(c.dec, objects, maxItems, filter)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfDynamicObjectsOffset defines the next field as a dynamic slice of
// dynamic ssz objects.
func DefineSliceOfDynamicObjectsOffset[T newableDynamicObject[U], U any](c *Codec, objects *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfDynamicObjectsOffset(c.enc, *objects)
return
}
if c.dec != nil {
DecodeSliceOfDynamicObjectsOffset(c.dec, objects)
return
}
HashSliceOfDynamicObjects(c.has, *objects, maxItems)
}
// DefineSliceOfDynamicObjectsOffsetOnFork defines the next field as a dynamic
// slice of dynamic ssz objects if present in a fork.
func DefineSliceOfDynamicObjectsOffsetOnFork[T newableDynamicObject[U], U any](c *Codec, objects *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfDynamicObjectsOffsetOnFork(c.enc, *objects, filter)
return
}
if c.dec != nil {
DecodeSliceOfDynamicObjectsOffsetOnFork(c.dec, objects, filter)
return
}
HashSliceOfDynamicObjectsOnFork(c.has, *objects, maxItems, filter)
}
// DefineSliceOfDynamicObjectsContent defines the next field as a dynamic slice
// of dynamic ssz objects.
func DefineSliceOfDynamicObjectsContent[T newableDynamicObject[U], U any](c *Codec, objects *[]T, maxItems uint64) {
if c.enc != nil {
EncodeSliceOfDynamicObjectsContent(c.enc, *objects)
return
}
if c.dec != nil {
DecodeSliceOfDynamicObjectsContent(c.dec, objects, maxItems)
return
}
// No hashing, done at the offset position
}
// DefineSliceOfDynamicObjectsContentOnFork defines the next field as a dynamic
// slice of dynamic ssz objects if present in a fork.
func DefineSliceOfDynamicObjectsContentOnFork[T newableDynamicObject[U], U any](c *Codec, objects *[]T, maxItems uint64, filter ForkFilter) {
if c.enc != nil {
EncodeSliceOfDynamicObjectsContentOnFork(c.enc, *objects, filter)
return
}
if c.dec != nil {
DecodeSliceOfDynamicObjectsContentOnFork(c.dec, objects, maxItems, filter)
return
}
// No hashing, done at the offset position
}