github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/network/payload/mptdata.go (about)

     1  package payload
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/nspcc-dev/neo-go/pkg/io"
     7  )
     8  
     9  // MPTData represents a set of serialized MPT nodes.
    10  type MPTData struct {
    11  	Nodes [][]byte
    12  }
    13  
    14  // EncodeBinary implements io.Serializable.
    15  func (d *MPTData) EncodeBinary(w *io.BinWriter) {
    16  	w.WriteVarUint(uint64(len(d.Nodes)))
    17  	for _, n := range d.Nodes {
    18  		w.WriteVarBytes(n)
    19  	}
    20  }
    21  
    22  // DecodeBinary implements io.Serializable.
    23  func (d *MPTData) DecodeBinary(r *io.BinReader) {
    24  	sz := r.ReadVarUint()
    25  	if sz == 0 {
    26  		r.Err = errors.New("empty MPT nodes list")
    27  		return
    28  	}
    29  	for i := uint64(0); i < sz; i++ {
    30  		d.Nodes = append(d.Nodes, r.ReadVarBytes())
    31  		if r.Err != nil {
    32  			return
    33  		}
    34  	}
    35  }