github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/network/payload/getblocks.go (about) 1 package payload 2 3 import ( 4 "errors" 5 6 "github.com/nspcc-dev/neo-go/pkg/io" 7 "github.com/nspcc-dev/neo-go/pkg/util" 8 ) 9 10 // Maximum inventory hashes number is limited to 500. 11 const ( 12 MaxHashesCount = 500 13 ) 14 15 // GetBlocks contains getblocks message payload fields. 16 type GetBlocks struct { 17 // Hash of the latest block that node requests. 18 HashStart util.Uint256 19 Count int16 20 } 21 22 // NewGetBlocks returns a pointer to a GetBlocks object. 23 func NewGetBlocks(start util.Uint256, count int16) *GetBlocks { 24 return &GetBlocks{ 25 HashStart: start, 26 Count: count, 27 } 28 } 29 30 // DecodeBinary implements the Serializable interface. 31 func (p *GetBlocks) DecodeBinary(br *io.BinReader) { 32 p.HashStart.DecodeBinary(br) 33 p.Count = int16(br.ReadU16LE()) 34 if p.Count < -1 || p.Count == 0 { 35 br.Err = errors.New("invalid count") 36 } 37 } 38 39 // EncodeBinary implements the Serializable interface. 40 func (p *GetBlocks) EncodeBinary(bw *io.BinWriter) { 41 p.HashStart.EncodeBinary(bw) 42 bw.WriteU16LE(uint16(p.Count)) 43 }