io: rename ReadBytes() to ReadVarBytes()

This commit is contained in:
Evgenii Stratonikov 2019-12-06 18:37:37 +03:00
parent f01fc1cc29
commit 838050f8b5
14 changed files with 22 additions and 22 deletions

View file

@ -217,7 +217,7 @@ func (p *Payload) DecodeBinaryUnsigned(r *io.BinReader) {
r.ReadLE(&p.validatorIndex)
r.ReadLE(&p.timestamp)
data := r.ReadBytes()
data := r.ReadVarBytes()
if r.Err != nil {
return
}

View file

@ -93,7 +93,7 @@ func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
r.ReadLE(&p.ValidatorIndex)
r.ReadLE(&p.OriginalViewNumber)
r.ReadLE(&p.Timestamp)
p.InvocationScript = r.ReadBytes()
p.InvocationScript = r.ReadVarBytes()
}
// EncodeBinary implements io.Serializable interface.
@ -109,7 +109,7 @@ func (p *commitCompact) DecodeBinary(r *io.BinReader) {
r.ReadLE(&p.ViewNumber)
r.ReadLE(&p.ValidatorIndex)
r.ReadBE(p.Signature[:])
p.InvocationScript = r.ReadBytes()
p.InvocationScript = r.ReadVarBytes()
}
// EncodeBinary implements io.Serializable interface.
@ -123,7 +123,7 @@ func (p *commitCompact) EncodeBinary(w *io.BinWriter) {
// DecodeBinary implements io.Serializable interface.
func (p *preparationCompact) DecodeBinary(r *io.BinReader) {
r.ReadLE(&p.ValidatorIndex)
p.InvocationScript = r.ReadBytes()
p.InvocationScript = r.ReadVarBytes()
}
// EncodeBinary implements io.Serializable interface.

View file

@ -38,7 +38,7 @@ func (a Contracts) commit(store storage.Store) error {
// DecodeBinary implements Serializable interface.
func (cs *ContractState) DecodeBinary(br *io.BinReader) {
cs.Script = br.ReadBytes()
cs.Script = br.ReadVarBytes()
br.ReadArray(&cs.ParamList)
br.ReadLE(&cs.ReturnType)
br.ReadLE(&cs.Properties)

View file

@ -59,6 +59,6 @@ func (si *StorageItem) EncodeBinary(w *io.BinWriter) {
// DecodeBinary implements Serializable interface.
func (si *StorageItem) DecodeBinary(r *io.BinReader) {
si.Value = r.ReadBytes()
si.Value = r.ReadVarBytes()
r.ReadLE(&si.IsConst)
}

View file

@ -35,7 +35,7 @@ func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction {
// DecodeBinary implements Serializable interface.
func (tx *InvocationTX) DecodeBinary(br *io.BinReader) {
tx.Script = br.ReadBytes()
tx.Script = br.ReadVarBytes()
if tx.Version >= 1 {
br.ReadLE(&tx.Gas)
} else {

View file

@ -22,7 +22,7 @@ type PublishTX struct {
// DecodeBinary implements Serializable interface.
func (tx *PublishTX) DecodeBinary(br *io.BinReader) {
tx.Script = br.ReadBytes()
tx.Script = br.ReadVarBytes()
lenParams := br.ReadVarUint()
tx.ParamList = make([]smartcontract.ParamType, lenParams)

View file

@ -25,8 +25,8 @@ type StateDescriptor struct {
func (s *StateDescriptor) DecodeBinary(r *io.BinReader) {
r.ReadLE(&s.Type)
s.Key = r.ReadBytes()
s.Value = r.ReadBytes()
s.Key = r.ReadVarBytes()
s.Value = r.ReadVarBytes()
s.Field = r.ReadString()
}

View file

@ -17,8 +17,8 @@ type Witness struct {
// DecodeBinary implements Serializable interface.
func (w *Witness) DecodeBinary(br *io.BinReader) {
w.InvocationScript = br.ReadBytes()
w.VerificationScript = br.ReadBytes()
w.InvocationScript = br.ReadVarBytes()
w.VerificationScript = br.ReadVarBytes()
}
// EncodeBinary implements Serializable interface.

View file

@ -127,17 +127,17 @@ func (r *BinReader) ReadVarUint() uint64 {
return uint64(b)
}
// ReadBytes reads the next set of bytes from the underlying reader.
// ReadVarBytes reads the next set of bytes from the underlying reader.
// ReadVarUInt() is used to determine how large that slice is
func (r *BinReader) ReadBytes() []byte {
func (r *BinReader) ReadVarBytes() []byte {
n := r.ReadVarUint()
b := make([]byte, n)
r.ReadLE(b)
return b
}
// ReadString calls ReadBytes and casts the results as a string.
// ReadString calls ReadVarBytes and casts the results as a string.
func (r *BinReader) ReadString() string {
b := r.ReadBytes()
b := r.ReadVarBytes()
return string(b)
}

View file

@ -91,7 +91,7 @@ func TestReaderErrHandling(t *testing.T) {
assert.Equal(t, i, iorig)
val := br.ReadVarUint()
assert.Equal(t, val, uint64(0))
b := br.ReadBytes()
b := br.ReadVarBytes()
assert.Equal(t, b, []byte{})
s := br.ReadString()
assert.Equal(t, s, "")

View file

@ -21,7 +21,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
m.TxCount = int(br.ReadVarUint())
br.ReadArray(&m.Hashes)
m.Flags = br.ReadBytes()
m.Flags = br.ReadVarBytes()
}
// EncodeBinary implements Serializable interface.

View file

@ -60,7 +60,7 @@ func (p *Version) DecodeBinary(br *io.BinReader) {
br.ReadLE(&p.Timestamp)
br.ReadLE(&p.Port)
br.ReadLE(&p.Nonce)
p.UserAgent = br.ReadBytes()
p.UserAgent = br.ReadVarBytes()
br.ReadLE(&p.StartHeight)
br.ReadLE(&p.Relay)
}

View file

@ -27,7 +27,7 @@ func TestCreateMultiSigRedeemScript(t *testing.T) {
assert.Equal(t, opcode.PUSH3, opcode.Opcode(b))
for i := 0; i < len(validators); i++ {
bb := br.ReadBytes()
bb := br.ReadVarBytes()
if br.Err != nil {
t.Fatal(err)
}

View file

@ -102,14 +102,14 @@ func DecodeBinaryStackItem(r *io.BinReader) StackItem {
switch stackItemType(t) {
case byteArrayT:
data := r.ReadBytes()
data := r.ReadVarBytes()
return NewByteArrayItem(data)
case booleanT:
var b bool
r.ReadLE(&b)
return NewBoolItem(b)
case integerT:
data := r.ReadBytes()
data := r.ReadVarBytes()
num := new(big.Int).SetBytes(util.ArrayReverse(data))
return &BigIntegerItem{
value: num,