-
Notifications
You must be signed in to change notification settings - Fork 8
/
generics.go
74 lines (67 loc) · 3.21 KB
/
generics.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
// ssz: Go Simple Serialize (SSZ) codec library
// Copyright 2024 ssz Authors
// SPDX-License-Identifier: BSD-3-Clause
package ssz
// newableStaticObject is a generic type whose purpose is to enforce that the
// ssz.StaticObject is specifically implemented on a struct pointer. That is
// needed to allow to instantiate new structs via `new` when parsing.
type newableStaticObject[U any] interface {
StaticObject
*U
}
// newableDynamicObject is a generic type whose purpose is to enforce that the
// ssz.DynamicObject is specifically implemented on a struct pointer. That is
// needed to allow to instantiate new structs via `new` when parsing.
type newableDynamicObject[U any] interface {
DynamicObject
*U
}
// commonBytesLengths is a generic type whose purpose is to permit that fixed-
// sized binary blobs can be passed to different methods. Although a slice of
// the array would work for simple cases, there are scenarios when a new array
// needs to be instantiated (e.g. optional field), and in that case we cannot
// operate on slices anymore as there's nothing yet to slice.
//
// You can add any size to this list really, it's just a limitation of the Go
// generics compiler that it cannot represent arrays of arbitrary sizes with
// one shorthand notation.
type commonBytesLengths interface {
// fork | nonce | address | verkle-stem | hash | pubkey | committee | signature | bloom
~[4]byte | ~[8]byte | ~[20]byte | ~[31]byte | ~[32]byte | ~[48]byte | ~[64]byte | ~[96]byte | ~[256]byte
}
// commonUint64sLengths is a generic type whose purpose is to permit that fixed-
// sized uint64 arrays can be passed to different methods. Although a slice of
// the array would work for simple cases, there are scenarios when a new array
// needs to be instantiated (e.g. optional field), and in that case we cannot
// operate on slices anymore as there's nothing yet to slice.
//
// You can add any size to this list really, it's just a limitation of the Go
// generics compiler that it cannot represent arrays of arbitrary sizes with
// one shorthand notation.
type commonUint64sLengths interface {
// slashing
~[8192]uint64
}
// commonBitsLengths is a generic type whose purpose is to permit that fixed-
// sized bit-vectors can be passed to different methods. Although a slice of
// the array would work for simple cases, there are scenarios when a new array
// needs to be instantiated (e.g. optional field), and in that case we cannot
// operate on slices anymore as there's nothing yet to slice.
//
// You can add any size to this list really, it's just a limitation of the Go
// generics compiler that it cannot represent arrays of arbitrary sizes with
// one shorthand notation.
type commonBitsLengths interface {
// justification
~[1]byte
}
// commonBytesArrayLengths is a generic type whose purpose is to permit that
// lists of different fixed-sized binary blob arrays can be passed to methods.
//
// You can add any size to this list really, it's just a limitation of the Go
// generics compiler that it cannot represent arrays of arbitrary sizes with
// one shorthand notation.
type commonBytesArrayLengths[U commonBytesLengths] interface {
// verkle IPA vectors | proof | committee | history | randao
~[8]U | ~[33]U | ~[512]U | ~[8192]U | ~[65536]U
}