57}
58
59// SizeSSZ --
60func (g *Gwei) SizeSSZ() int {61 return 8
62}
63
51}
52
53// MarshalSSZ --
54func (g *Gwei) MarshalSSZ() ([]byte, error) {55 marshalled := fssz.MarshalUint64([]byte{}, uint64(*g))
56 return marshalled, nil
57}
42}
43
44// MarshalSSZTo --
45func (g *Gwei) MarshalSSZTo(dst []byte) ([]byte, error) {46 marshalled, err := g.MarshalSSZ()
47 if err != nil {
48 return nil, err
33}
34
35// UnmarshalSSZ --
36func (g *Gwei) UnmarshalSSZ(buf []byte) error {37 if len(buf) != g.SizeSSZ() {
38 return fmt.Errorf("expected buffer of length %d received %d", g.SizeSSZ(), len(buf))
39 }
27}
28
29// HashTreeRootWith --
30func (g Gwei) HashTreeRootWith(hh *fssz.Hasher) error {31 hh.PutUint64(uint64(g))
32 return nil
33}
(Go's FAQ)[https://go.dev/doc/faq#methodsonvaluesorpointers] recommends that method receivers should be consistent. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used. This is because value and pointer receivers have different method sets.
package main
type foo struct {
a int
}
func (f foo) a() {}
func (f *foo) b() {
f.a = 10
}
package main
type foo struct {
a int
}
func (f *foo) a() {}
func (f *foo) b() {
f.a = 10
}