-
Notifications
You must be signed in to change notification settings - Fork 59
/
fork_encoding.go
75 lines (56 loc) · 1.59 KB
/
fork_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
// Code generated by fastssz. DO NOT EDIT.
package phase0
import (
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the Fork object
func (f *Fork) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(f)
}
// MarshalSSZTo ssz marshals the Fork object to a target array
func (f *Fork) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'PreviousVersion'
dst = append(dst, f.PreviousVersion[:]...)
// Field (1) 'CurrentVersion'
dst = append(dst, f.CurrentVersion[:]...)
// Field (2) 'Epoch'
dst = ssz.MarshalUint64(dst, uint64(f.Epoch))
return
}
// UnmarshalSSZ ssz unmarshals the Fork object
func (f *Fork) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 16 {
return ssz.ErrSize
}
// Field (0) 'PreviousVersion'
copy(f.PreviousVersion[:], buf[0:4])
// Field (1) 'CurrentVersion'
copy(f.CurrentVersion[:], buf[4:8])
// Field (2) 'Epoch'
f.Epoch = Epoch(ssz.UnmarshallUint64(buf[8:16]))
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the Fork object
func (f *Fork) SizeSSZ() (size int) {
size = 16
return
}
// HashTreeRoot ssz hashes the Fork object
func (f *Fork) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(f)
}
// HashTreeRootWith ssz hashes the Fork object with a hasher
func (f *Fork) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'PreviousVersion'
hh.PutBytes(f.PreviousVersion[:])
// Field (1) 'CurrentVersion'
hh.PutBytes(f.CurrentVersion[:])
// Field (2) 'Epoch'
hh.PutUint64(uint64(f.Epoch))
hh.Merkleize(indx)
return
}