forked from ferranbt/fastssz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigint_encoding.go
90 lines (75 loc) · 2.26 KB
/
bigint_encoding.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
// Code generated by fastssz. DO NOT EDIT.
// Hash: 0f0655ec701db4de9479b122ccc9152b370be9116b2814917810ca4334239411
// Version: 0.1.3
package testcases
import (
ssz "github.com/anukul/fastssz"
)
// MarshalSSZ ssz marshals the BigIntType object
func (b *BigIntType) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(b)
}
// MarshalSSZTo ssz marshals the BigIntType object to a target array
func (b *BigIntType) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'BigInt'
bitLength := b.BigInt.BitLen()
// The minimal byte length is bitLength rounded up
// to the next multiple of 8, divided by 8.
requiredLength := ((bitLength + 7) & -8) >> 3
if 129 < requiredLength {
err = ssz.ErrBigIntTooBigFn("BigIntType.BigInt", requiredLength, 129)
return
}
dst = ssz.MarshalBigInt(dst, b.BigInt)
return
}
// UnmarshalSSZ ssz unmarshals the BigIntType object
func (b *BigIntType) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 129 {
return ssz.ErrSize
}
// Field (0) 'BigInt'
if err = ssz.ValidateBigInt(b.BigInt, 129); err != nil {
return err
}
b.BigInt = ssz.UnmarshalBigInt(buf[0:129])
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the BigIntType object
func (b *BigIntType) SizeSSZ() (size int) {
size = 129
return
}
// HashTreeRoot ssz hashes the BigIntType object
func (b *BigIntType) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(b)
}
// HashTreeRootWith ssz hashes the BigIntType object with a hasher
func (b *BigIntType) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'BigInt'
bitLength := b.BigInt.BitLen()
// The minimal byte length is bitLength rounded up
// to the next multiple of 8, divided by 8.
requiredLength := ((bitLength + 7) & -8) >> 3
if 129 < requiredLength {
err = ssz.ErrBigIntTooBigFn("BigIntType.BigInt", requiredLength, 129)
return
}
dst := make([]byte, 129)
dst = b.BigInt.FillBytes(dst)
// Reverse dst to little endian byte order
for i, j := 0, len(dst)-1; i < j; i, j = i+1, j-1 {
dst[i], dst[j] = dst[j], dst[i]
}
hh.PutBytes(dst)
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the BigIntType object
func (b *BigIntType) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(b)
}