forked from ferranbt/fastssz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_encoding.go
137 lines (104 loc) · 3.02 KB
/
time_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Code generated by fastssz. DO NOT EDIT.
// Hash: 04ac916e8f15c6e500617c8195a73e18b9b9f9a76652d4bec1f96b4bb045bef4
package testcases
import (
ssz "github.com/MEV-HEPU/fastssz"
)
// MarshalSSZ ssz marshals the TimeType object
func (t *TimeType) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(t)
}
// MarshalSSZTo ssz marshals the TimeType object to a target array
func (t *TimeType) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'Timestamp'
dst = ssz.MarshalTime(dst, t.Timestamp)
// Field (1) 'Int'
dst = ssz.MarshalUint64(dst, t.Int)
return
}
// UnmarshalSSZ ssz unmarshals the TimeType object
func (t *TimeType) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 16 {
return ssz.ErrSize
}
// Field (0) 'Timestamp'
t.Timestamp = ssz.UnmarshalTime(buf[0:8])
// Field (1) 'Int'
t.Int = ssz.UnmarshallUint64(buf[8:16])
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the TimeType object
func (t *TimeType) SizeSSZ() (size int) {
size = 16
return
}
// HashTreeRoot ssz hashes the TimeType object
func (t *TimeType) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(t)
}
// HashTreeRootWith ssz hashes the TimeType object with a hasher
func (t *TimeType) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'Timestamp'
hh.PutUint64(uint64(t.Timestamp.Unix()))
// Field (1) 'Int'
hh.PutUint64(t.Int)
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the TimeType object
func (t *TimeType) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(t)
}
// MarshalSSZ ssz marshals the TimeRawType object
func (t *TimeRawType) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(t)
}
// MarshalSSZTo ssz marshals the TimeRawType object to a target array
func (t *TimeRawType) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'Timestamp'
dst = ssz.MarshalUint64(dst, t.Timestamp)
// Field (1) 'Int'
dst = ssz.MarshalUint64(dst, t.Int)
return
}
// UnmarshalSSZ ssz unmarshals the TimeRawType object
func (t *TimeRawType) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 16 {
return ssz.ErrSize
}
// Field (0) 'Timestamp'
t.Timestamp = ssz.UnmarshallUint64(buf[0:8])
// Field (1) 'Int'
t.Int = ssz.UnmarshallUint64(buf[8:16])
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the TimeRawType object
func (t *TimeRawType) SizeSSZ() (size int) {
size = 16
return
}
// HashTreeRoot ssz hashes the TimeRawType object
func (t *TimeRawType) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(t)
}
// HashTreeRootWith ssz hashes the TimeRawType object with a hasher
func (t *TimeRawType) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'Timestamp'
hh.PutUint64(t.Timestamp)
// Field (1) 'Int'
hh.PutUint64(t.Int)
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the TimeRawType object
func (t *TimeRawType) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(t)
}