/
committee_index.go
54 lines (44 loc) · 1.24 KB
/
committee_index.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
package primitives
import (
"fmt"
fssz "github.com/prysmaticlabs/fastssz"
)
var _ fssz.HashRoot = (CommitteeIndex)(0)
var _ fssz.Marshaler = (*CommitteeIndex)(nil)
var _ fssz.Unmarshaler = (*CommitteeIndex)(nil)
// CommitteeIndex --
type CommitteeIndex uint64
// HashTreeRoot returns calculated hash root.
func (c CommitteeIndex) HashTreeRoot() ([32]byte, error) {
return fssz.HashWithDefaultHasher(c)
}
// HashTreeRootWith --
func (c CommitteeIndex) HashTreeRootWith(hh *fssz.Hasher) error {
hh.PutUint64(uint64(c))
return nil
}
// UnmarshalSSZ --
func (c *CommitteeIndex) UnmarshalSSZ(buf []byte) error {
if len(buf) != c.SizeSSZ() {
return fmt.Errorf("expected buffer of length %d receiced %d", c.SizeSSZ(), len(buf))
}
*c = CommitteeIndex(fssz.UnmarshallUint64(buf))
return nil
}
// MarshalSSZTo --
func (c *CommitteeIndex) MarshalSSZTo(dst []byte) ([]byte, error) {
marshalled, err := c.MarshalSSZ()
if err != nil {
return nil, err
}
return append(dst, marshalled...), nil
}
// MarshalSSZ --
func (c *CommitteeIndex) MarshalSSZ() ([]byte, error) {
marshalled := fssz.MarshalUint64([]byte{}, uint64(*c))
return marshalled, nil
}
// SizeSSZ returns the size of the serialized object.
func (c *CommitteeIndex) SizeSSZ() int {
return 8
}