mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-01 23:45:50 +00:00
1b83dc2476
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also prefers ranging over slices where possible (it makes code a little better to read). Notice that we have a number of dangerous loops where slices are mutated during loop execution, many of these can't be converted since we need proper length evalutation at every iteration. Signed-off-by: Roman Khimov <roman@nspcc.ru>
35 lines
649 B
Go
35 lines
649 B
Go
package payload
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
)
|
|
|
|
// MPTData represents a set of serialized MPT nodes.
|
|
type MPTData struct {
|
|
Nodes [][]byte
|
|
}
|
|
|
|
// EncodeBinary implements io.Serializable.
|
|
func (d *MPTData) EncodeBinary(w *io.BinWriter) {
|
|
w.WriteVarUint(uint64(len(d.Nodes)))
|
|
for _, n := range d.Nodes {
|
|
w.WriteVarBytes(n)
|
|
}
|
|
}
|
|
|
|
// DecodeBinary implements io.Serializable.
|
|
func (d *MPTData) DecodeBinary(r *io.BinReader) {
|
|
sz := r.ReadVarUint()
|
|
if sz == 0 {
|
|
r.Err = errors.New("empty MPT nodes list")
|
|
return
|
|
}
|
|
for range sz {
|
|
d.Nodes = append(d.Nodes, r.ReadVarBytes())
|
|
if r.Err != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|