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

     1  package payload
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/nspcc-dev/neo-go/pkg/io"
     7  )
     8  
     9  // GetBlockByIndex payload.
    10  type GetBlockByIndex struct {
    11  	IndexStart uint32
    12  	Count      int16
    13  }
    14  
    15  // NewGetBlockByIndex returns GetBlockByIndex payload with the specified start index and count.
    16  func NewGetBlockByIndex(indexStart uint32, count int16) *GetBlockByIndex {
    17  	return &GetBlockByIndex{
    18  		IndexStart: indexStart,
    19  		Count:      count,
    20  	}
    21  }
    22  
    23  // DecodeBinary implements the Serializable interface.
    24  func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
    25  	d.IndexStart = br.ReadU32LE()
    26  	d.Count = int16(br.ReadU16LE())
    27  	if d.Count < -1 || d.Count == 0 || d.Count > MaxHeadersAllowed {
    28  		br.Err = fmt.Errorf("invalid block count: %d", d.Count)
    29  	}
    30  }
    31  
    32  // EncodeBinary implements the Serializable interface.
    33  func (d *GetBlockByIndex) EncodeBinary(bw *io.BinWriter) {
    34  	bw.WriteU32LE(d.IndexStart)
    35  	bw.WriteU16LE(uint16(d.Count))
    36  }