github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/pkg/stafidecoder/scaleBytes.go (about)

     1  package stafi_decoder
     2  
     3  import (
     4  	"github.com/itering/scale.go/utiles"
     5  )
     6  
     7  type ScaleBytes struct {
     8  	Data   []byte `json:"data"`
     9  	Offset int    `json:"offset"`
    10  }
    11  
    12  func (s *ScaleBytes) GetNextBytes(length int) []byte {
    13  	if s.Offset+length > len(s.Data) {
    14  		data := s.Data[s.Offset:]
    15  		s.Offset = len(s.Data)
    16  		return data
    17  	}
    18  	data := s.Data[s.Offset : s.Offset+length]
    19  	s.Offset = s.Offset + length
    20  	return data
    21  }
    22  
    23  func (s *ScaleBytes) GetRemainingLength() int {
    24  	return len(s.Data) - s.Offset
    25  }
    26  
    27  func (s *ScaleBytes) String() string {
    28  	return utiles.AddHex(utiles.BytesToHex(s.Data))
    29  }
    30  
    31  func (s *ScaleBytes) Reset() {
    32  	s.Offset = 0
    33  }