io: rename Read/WriteBytes to Read/WriteB

go vet is not happy about them:
  pkg/io/binaryReader.go:92:21: method ReadByte() byte should have signature ReadByte() (byte, error)
  pkg/io/binaryWriter.go:75:21: method WriteByte(u8 byte) should have signature WriteByte(byte) error
This commit is contained in:
Roman Khimov 2019-12-12 20:17:50 +03:00
parent 0b14916d79
commit 8b3080b972
22 changed files with 70 additions and 70 deletions

View file

@ -176,7 +176,7 @@ func (p *Payload) EncodeBinaryUnsigned(w *io.BinWriter) {
func (p *Payload) EncodeBinary(w *io.BinWriter) { func (p *Payload) EncodeBinary(w *io.BinWriter) {
p.EncodeBinaryUnsigned(w) p.EncodeBinaryUnsigned(w)
w.WriteByte(1) w.WriteB(1)
p.Witness.EncodeBinary(w) p.Witness.EncodeBinary(w)
} }
@ -242,7 +242,7 @@ func (p *Payload) DecodeBinary(r *io.BinReader) {
return return
} }
var b = r.ReadByte() var b = r.ReadB()
if b != 1 { if b != 1 {
r.Err = errors.New("invalid format") r.Err = errors.New("invalid format")
return return
@ -254,14 +254,14 @@ func (p *Payload) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (m *message) EncodeBinary(w *io.BinWriter) { func (m *message) EncodeBinary(w *io.BinWriter) {
w.WriteBytes([]byte{byte(m.Type)}) w.WriteBytes([]byte{byte(m.Type)})
w.WriteByte(m.ViewNumber) w.WriteB(m.ViewNumber)
m.payload.EncodeBinary(w) m.payload.EncodeBinary(w)
} }
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (m *message) DecodeBinary(r *io.BinReader) { func (m *message) DecodeBinary(r *io.BinReader) {
m.Type = messageType(r.ReadByte()) m.Type = messageType(r.ReadB())
m.ViewNumber = r.ReadByte() m.ViewNumber = r.ReadB()
switch m.Type { switch m.Type {
case changeViewType: case changeViewType:

View file

@ -90,7 +90,7 @@ func (m *recoveryMessage) EncodeBinary(w *io.BinWriter) {
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (p *changeViewCompact) DecodeBinary(r *io.BinReader) { func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
p.ValidatorIndex = r.ReadU16LE() p.ValidatorIndex = r.ReadU16LE()
p.OriginalViewNumber = r.ReadByte() p.OriginalViewNumber = r.ReadB()
p.Timestamp = r.ReadU32LE() p.Timestamp = r.ReadU32LE()
p.InvocationScript = r.ReadVarBytes() p.InvocationScript = r.ReadVarBytes()
} }
@ -98,14 +98,14 @@ func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (p *changeViewCompact) EncodeBinary(w *io.BinWriter) { func (p *changeViewCompact) EncodeBinary(w *io.BinWriter) {
w.WriteU16LE(p.ValidatorIndex) w.WriteU16LE(p.ValidatorIndex)
w.WriteByte(p.OriginalViewNumber) w.WriteB(p.OriginalViewNumber)
w.WriteU32LE(p.Timestamp) w.WriteU32LE(p.Timestamp)
w.WriteVarBytes(p.InvocationScript) w.WriteVarBytes(p.InvocationScript)
} }
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (p *commitCompact) DecodeBinary(r *io.BinReader) { func (p *commitCompact) DecodeBinary(r *io.BinReader) {
p.ViewNumber = r.ReadByte() p.ViewNumber = r.ReadB()
p.ValidatorIndex = r.ReadU16LE() p.ValidatorIndex = r.ReadU16LE()
r.ReadBytes(p.Signature[:]) r.ReadBytes(p.Signature[:])
p.InvocationScript = r.ReadVarBytes() p.InvocationScript = r.ReadVarBytes()
@ -113,7 +113,7 @@ func (p *commitCompact) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (p *commitCompact) EncodeBinary(w *io.BinWriter) { func (p *commitCompact) EncodeBinary(w *io.BinWriter) {
w.WriteByte(p.ViewNumber) w.WriteB(p.ViewNumber)
w.WriteU16LE(p.ValidatorIndex) w.WriteU16LE(p.ValidatorIndex)
w.WriteBytes(p.Signature[:]) w.WriteBytes(p.Signature[:])
w.WriteVarBytes(p.InvocationScript) w.WriteVarBytes(p.InvocationScript)

View file

@ -88,7 +88,7 @@ func NewBlockFromTrimmedBytes(b []byte) (*Block, error) {
br := io.NewBinReaderFromBuf(b) br := io.NewBinReaderFromBuf(b)
block.decodeHashableFields(br) block.decodeHashableFields(br)
_ = br.ReadByte() _ = br.ReadB()
block.Script.DecodeBinary(br) block.Script.DecodeBinary(br)
@ -109,7 +109,7 @@ func NewBlockFromTrimmedBytes(b []byte) (*Block, error) {
func (b *Block) Trim() ([]byte, error) { func (b *Block) Trim() ([]byte, error) {
buf := io.NewBufBinWriter() buf := io.NewBufBinWriter()
b.encodeHashableFields(buf.BinWriter) b.encodeHashableFields(buf.BinWriter)
buf.WriteByte(1) buf.WriteB(1)
b.Script.EncodeBinary(buf.BinWriter) b.Script.EncodeBinary(buf.BinWriter)
buf.WriteVarUint(uint64(len(b.Transactions))) buf.WriteVarUint(uint64(len(b.Transactions)))

View file

@ -39,7 +39,7 @@ func NewAccount(scriptHash util.Uint160) *Account {
// DecodeBinary decodes Account from the given BinReader. // DecodeBinary decodes Account from the given BinReader.
func (s *Account) DecodeBinary(br *io.BinReader) { func (s *Account) DecodeBinary(br *io.BinReader) {
s.Version = uint8(br.ReadByte()) s.Version = uint8(br.ReadB())
br.ReadBytes(s.ScriptHash[:]) br.ReadBytes(s.ScriptHash[:])
s.IsFrozen = br.ReadBool() s.IsFrozen = br.ReadBool()
br.ReadArray(&s.Votes) br.ReadArray(&s.Votes)
@ -57,7 +57,7 @@ func (s *Account) DecodeBinary(br *io.BinReader) {
// EncodeBinary encodes Account to the given BinWriter. // EncodeBinary encodes Account to the given BinWriter.
func (s *Account) EncodeBinary(bw *io.BinWriter) { func (s *Account) EncodeBinary(bw *io.BinWriter) {
bw.WriteByte(byte(s.Version)) bw.WriteB(byte(s.Version))
bw.WriteBytes(s.ScriptHash[:]) bw.WriteBytes(s.ScriptHash[:])
bw.WriteBool(s.IsFrozen) bw.WriteBool(s.IsFrozen)
bw.WriteArray(s.Votes) bw.WriteArray(s.Votes)

View file

@ -29,14 +29,14 @@ type Asset struct {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (a *Asset) DecodeBinary(br *io.BinReader) { func (a *Asset) DecodeBinary(br *io.BinReader) {
br.ReadBytes(a.ID[:]) br.ReadBytes(a.ID[:])
a.AssetType = transaction.AssetType(br.ReadByte()) a.AssetType = transaction.AssetType(br.ReadB())
a.Name = br.ReadString() a.Name = br.ReadString()
a.Amount.DecodeBinary(br) a.Amount.DecodeBinary(br)
a.Available.DecodeBinary(br) a.Available.DecodeBinary(br)
a.Precision = uint8(br.ReadByte()) a.Precision = uint8(br.ReadB())
a.FeeMode = uint8(br.ReadByte()) a.FeeMode = uint8(br.ReadB())
br.ReadBytes(a.FeeAddress[:]) br.ReadBytes(a.FeeAddress[:])
a.Owner.DecodeBinary(br) a.Owner.DecodeBinary(br)
@ -49,12 +49,12 @@ func (a *Asset) DecodeBinary(br *io.BinReader) {
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (a *Asset) EncodeBinary(bw *io.BinWriter) { func (a *Asset) EncodeBinary(bw *io.BinWriter) {
bw.WriteBytes(a.ID[:]) bw.WriteBytes(a.ID[:])
bw.WriteByte(byte(a.AssetType)) bw.WriteB(byte(a.AssetType))
bw.WriteString(a.Name) bw.WriteString(a.Name)
a.Amount.EncodeBinary(bw) a.Amount.EncodeBinary(bw)
a.Available.EncodeBinary(bw) a.Available.EncodeBinary(bw)
bw.WriteByte(byte(a.Precision)) bw.WriteB(byte(a.Precision))
bw.WriteByte(byte(a.FeeMode)) bw.WriteB(byte(a.FeeMode))
bw.WriteBytes(a.FeeAddress[:]) bw.WriteBytes(a.FeeAddress[:])
a.Owner.EncodeBinary(bw) a.Owner.EncodeBinary(bw)

View file

@ -26,8 +26,8 @@ type Contract struct {
func (cs *Contract) DecodeBinary(br *io.BinReader) { func (cs *Contract) DecodeBinary(br *io.BinReader) {
cs.Script = br.ReadVarBytes() cs.Script = br.ReadVarBytes()
br.ReadArray(&cs.ParamList) br.ReadArray(&cs.ParamList)
cs.ReturnType = smartcontract.ParamType(br.ReadByte()) cs.ReturnType = smartcontract.ParamType(br.ReadB())
cs.Properties = smartcontract.PropertyState(br.ReadByte()) cs.Properties = smartcontract.PropertyState(br.ReadB())
cs.Name = br.ReadString() cs.Name = br.ReadString()
cs.CodeVersion = br.ReadString() cs.CodeVersion = br.ReadString()
cs.Author = br.ReadString() cs.Author = br.ReadString()
@ -40,8 +40,8 @@ func (cs *Contract) DecodeBinary(br *io.BinReader) {
func (cs *Contract) EncodeBinary(bw *io.BinWriter) { func (cs *Contract) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarBytes(cs.Script) bw.WriteVarBytes(cs.Script)
bw.WriteArray(cs.ParamList) bw.WriteArray(cs.ParamList)
bw.WriteByte(byte(cs.ReturnType)) bw.WriteB(byte(cs.ReturnType))
bw.WriteByte(byte(cs.Properties)) bw.WriteB(byte(cs.Properties))
bw.WriteString(cs.Name) bw.WriteString(cs.Name)
bw.WriteString(cs.CodeVersion) bw.WriteString(cs.CodeVersion)
bw.WriteString(cs.Author) bw.WriteString(cs.Author)

View file

@ -39,7 +39,7 @@ func (ne *NotificationEvent) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements the Serializable interface. // EncodeBinary implements the Serializable interface.
func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) { func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
w.WriteBytes(aer.TxHash[:]) w.WriteBytes(aer.TxHash[:])
w.WriteByte(aer.Trigger) w.WriteB(aer.Trigger)
w.WriteString(aer.VMState) w.WriteString(aer.VMState)
aer.GasConsumed.EncodeBinary(w) aer.GasConsumed.EncodeBinary(w)
w.WriteString(aer.Stack) w.WriteString(aer.Stack)
@ -49,7 +49,7 @@ func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
// DecodeBinary implements the Serializable interface. // DecodeBinary implements the Serializable interface.
func (aer *AppExecResult) DecodeBinary(r *io.BinReader) { func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
r.ReadBytes(aer.TxHash[:]) r.ReadBytes(aer.TxHash[:])
aer.Trigger = r.ReadByte() aer.Trigger = r.ReadB()
aer.VMState = r.ReadString() aer.VMState = r.ReadString()
aer.GasConsumed.DecodeBinary(r) aer.GasConsumed.DecodeBinary(r)
aer.Stack = r.ReadString() aer.Stack = r.ReadString()

View file

@ -16,7 +16,7 @@ type Attribute struct {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (attr *Attribute) DecodeBinary(br *io.BinReader) { func (attr *Attribute) DecodeBinary(br *io.BinReader) {
attr.Usage = AttrUsage(br.ReadByte()) attr.Usage = AttrUsage(br.ReadB())
// very special case // very special case
if attr.Usage == ECDH02 || attr.Usage == ECDH03 { if attr.Usage == ECDH02 || attr.Usage == ECDH03 {
@ -35,7 +35,7 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {
datasize = 20 datasize = 20
case DescriptionURL: case DescriptionURL:
// It's not VarUint as per C# implementation, dunno why // It's not VarUint as per C# implementation, dunno why
var urllen = br.ReadByte() var urllen = br.ReadB()
datasize = uint64(urllen) datasize = uint64(urllen)
case Description, Remark, Remark1, Remark2, Remark3, Remark4, case Description, Remark, Remark1, Remark2, Remark3, Remark4,
Remark5, Remark6, Remark7, Remark8, Remark9, Remark10, Remark11, Remark5, Remark6, Remark7, Remark8, Remark9, Remark10, Remark11,
@ -51,7 +51,7 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (attr *Attribute) EncodeBinary(bw *io.BinWriter) { func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
bw.WriteByte(byte(attr.Usage)) bw.WriteB(byte(attr.Usage))
switch attr.Usage { switch attr.Usage {
case ECDH02, ECDH03: case ECDH02, ECDH03:
bw.WriteBytes(attr.Data[1:]) bw.WriteBytes(attr.Data[1:])
@ -60,7 +60,7 @@ func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
Remark12, Remark13, Remark14, Remark15: Remark12, Remark13, Remark14, Remark15:
bw.WriteVarBytes(attr.Data) bw.WriteVarBytes(attr.Data)
case DescriptionURL: case DescriptionURL:
bw.WriteByte(byte(len(attr.Data))) bw.WriteB(byte(len(attr.Data)))
fallthrough fallthrough
case Script, ContractHash, Vote, Hash1, Hash2, Hash3, Hash4, Hash5, Hash6, case Script, ContractHash, Vote, Hash1, Hash2, Hash3, Hash4, Hash5, Hash6,
Hash7, Hash8, Hash9, Hash10, Hash11, Hash12, Hash13, Hash14, Hash15: Hash7, Hash8, Hash9, Hash10, Hash11, Hash12, Hash13, Hash14, Hash15:

View file

@ -27,10 +27,10 @@ func (tx *PublishTX) DecodeBinary(br *io.BinReader) {
lenParams := br.ReadVarUint() lenParams := br.ReadVarUint()
tx.ParamList = make([]smartcontract.ParamType, lenParams) tx.ParamList = make([]smartcontract.ParamType, lenParams)
for i := 0; i < int(lenParams); i++ { for i := 0; i < int(lenParams); i++ {
tx.ParamList[i] = smartcontract.ParamType(br.ReadByte()) tx.ParamList[i] = smartcontract.ParamType(br.ReadB())
} }
tx.ReturnType = smartcontract.ParamType(br.ReadByte()) tx.ReturnType = smartcontract.ParamType(br.ReadB())
if tx.Version >= 1 { if tx.Version >= 1 {
tx.NeedStorage = br.ReadBool() tx.NeedStorage = br.ReadBool()
@ -50,9 +50,9 @@ func (tx *PublishTX) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarBytes(tx.Script) bw.WriteVarBytes(tx.Script)
bw.WriteVarUint(uint64(len(tx.ParamList))) bw.WriteVarUint(uint64(len(tx.ParamList)))
for _, param := range tx.ParamList { for _, param := range tx.ParamList {
bw.WriteByte(byte(param)) bw.WriteB(byte(param))
} }
bw.WriteByte(byte(tx.ReturnType)) bw.WriteB(byte(tx.ReturnType))
if tx.Version >= 1 { if tx.Version >= 1 {
bw.WriteBool(tx.NeedStorage) bw.WriteBool(tx.NeedStorage)
} }

View file

@ -30,12 +30,12 @@ type RegisterTX struct {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *RegisterTX) DecodeBinary(br *io.BinReader) { func (tx *RegisterTX) DecodeBinary(br *io.BinReader) {
tx.AssetType = AssetType(br.ReadByte()) tx.AssetType = AssetType(br.ReadB())
tx.Name = br.ReadString() tx.Name = br.ReadString()
tx.Amount.DecodeBinary(br) tx.Amount.DecodeBinary(br)
tx.Precision = uint8(br.ReadByte()) tx.Precision = uint8(br.ReadB())
tx.Owner.DecodeBinary(br) tx.Owner.DecodeBinary(br)
@ -44,10 +44,10 @@ func (tx *RegisterTX) DecodeBinary(br *io.BinReader) {
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (tx *RegisterTX) EncodeBinary(bw *io.BinWriter) { func (tx *RegisterTX) EncodeBinary(bw *io.BinWriter) {
bw.WriteByte(byte(tx.AssetType)) bw.WriteB(byte(tx.AssetType))
bw.WriteString(tx.Name) bw.WriteString(tx.Name)
tx.Amount.EncodeBinary(bw) tx.Amount.EncodeBinary(bw)
bw.WriteByte(byte(tx.Precision)) bw.WriteB(byte(tx.Precision))
bw.WriteBytes(tx.Owner.Bytes()) bw.WriteBytes(tx.Owner.Bytes())
bw.WriteBytes(tx.Admin[:]) bw.WriteBytes(tx.Admin[:])
} }

View file

@ -23,7 +23,7 @@ type StateDescriptor struct {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (s *StateDescriptor) DecodeBinary(r *io.BinReader) { func (s *StateDescriptor) DecodeBinary(r *io.BinReader) {
s.Type = DescStateType(r.ReadByte()) s.Type = DescStateType(r.ReadB())
s.Key = r.ReadVarBytes() s.Key = r.ReadVarBytes()
s.Value = r.ReadVarBytes() s.Value = r.ReadVarBytes()
@ -32,7 +32,7 @@ func (s *StateDescriptor) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (s *StateDescriptor) EncodeBinary(w *io.BinWriter) { func (s *StateDescriptor) EncodeBinary(w *io.BinWriter) {
w.WriteByte(byte(s.Type)) w.WriteB(byte(s.Type))
w.WriteVarBytes(s.Key) w.WriteVarBytes(s.Key)
w.WriteVarBytes(s.Value) w.WriteVarBytes(s.Value)
w.WriteString(s.Field) w.WriteString(s.Field)

View file

@ -92,8 +92,8 @@ func (t *Transaction) AddInput(in *Input) {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (t *Transaction) DecodeBinary(br *io.BinReader) { func (t *Transaction) DecodeBinary(br *io.BinReader) {
t.Type = TXType(br.ReadByte()) t.Type = TXType(br.ReadB())
t.Version = uint8(br.ReadByte()) t.Version = uint8(br.ReadB())
t.decodeData(br) t.decodeData(br)
br.ReadArray(&t.Attributes) br.ReadArray(&t.Attributes)
@ -151,8 +151,8 @@ func (t *Transaction) EncodeBinary(bw *io.BinWriter) {
// encodeHashableFields encodes the fields that are not used for // encodeHashableFields encodes the fields that are not used for
// signing the transaction, which are all fields except the scripts. // signing the transaction, which are all fields except the scripts.
func (t *Transaction) encodeHashableFields(bw *io.BinWriter) { func (t *Transaction) encodeHashableFields(bw *io.BinWriter) {
bw.WriteByte(byte(t.Type)) bw.WriteB(byte(t.Type))
bw.WriteByte(byte(t.Version)) bw.WriteB(byte(t.Version))
// Underlying TXer. // Underlying TXer.
if t.Data != nil { if t.Data != nil {

View file

@ -25,7 +25,7 @@ func NewUnspentCoinState(n int) *UnspentCoinState {
func (s *UnspentCoinState) EncodeBinary(bw *io.BinWriter) { func (s *UnspentCoinState) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarUint(uint64(len(s.states))) bw.WriteVarUint(uint64(len(s.states)))
for _, state := range s.states { for _, state := range s.states {
bw.WriteByte(byte(state)) bw.WriteB(byte(state))
} }
} }
@ -34,6 +34,6 @@ func (s *UnspentCoinState) DecodeBinary(br *io.BinReader) {
lenStates := br.ReadVarUint() lenStates := br.ReadVarUint()
s.states = make([]state.Coin, lenStates) s.states = make([]state.Coin, lenStates)
for i := 0; i < int(lenStates); i++ { for i := 0; i < int(lenStates); i++ {
s.states[i] = state.Coin(br.ReadByte()) s.states[i] = state.Coin(br.ReadB())
} }
} }

View file

@ -168,7 +168,7 @@ func (p *PublicKey) DecodeBinary(r *io.BinReader) {
var x, y *big.Int var x, y *big.Int
var err error var err error
prefix = uint8(r.ReadByte()) prefix = uint8(r.ReadB())
if r.Err != nil { if r.Err != nil {
return return
} }

View file

@ -87,9 +87,9 @@ func (r *BinReader) ReadU16BE() uint16 {
return binary.BigEndian.Uint16(r.u16) return binary.BigEndian.Uint16(r.u16)
} }
// ReadByte reads a byte from the underlying io.Reader. On read failures it // ReadB reads a byte from the underlying io.Reader. On read failures it
// returns zero. // returns zero.
func (r *BinReader) ReadByte() byte { func (r *BinReader) ReadB() byte {
r.ReadBytes(r.u8) r.ReadBytes(r.u8)
if r.Err != nil { if r.Err != nil {
return 0 return 0
@ -100,7 +100,7 @@ func (r *BinReader) ReadByte() byte {
// ReadBool reads a boolean value encoded in a zero/non-zero byte from the // ReadBool reads a boolean value encoded in a zero/non-zero byte from the
// underlying io.Reader. On read failures it returns false. // underlying io.Reader. On read failures it returns false.
func (r *BinReader) ReadBool() bool { func (r *BinReader) ReadBool() bool {
return r.ReadByte() != 0 return r.ReadB() != 0
} }
// ReadArray reads array into value which must be // ReadArray reads array into value which must be
@ -169,7 +169,7 @@ func (r *BinReader) ReadVarUint() uint64 {
return 0 return 0
} }
var b = r.ReadByte() var b = r.ReadB()
if b == 0xfd { if b == 0xfd {
return uint64(r.ReadU16LE()) return uint64(r.ReadU16LE())

View file

@ -71,8 +71,8 @@ func (w *BinWriter) WriteU16BE(u16 uint16) {
w.WriteBytes(w.u16) w.WriteBytes(w.u16)
} }
// WriteByte writes a byte into the underlying io.Writer. // WriteB writes a byte into the underlying io.Writer.
func (w *BinWriter) WriteByte(u8 byte) { func (w *BinWriter) WriteB(u8 byte) {
w.u8[0] = u8 w.u8[0] = u8
w.WriteBytes(w.u8) w.WriteBytes(w.u8)
} }
@ -84,7 +84,7 @@ func (w *BinWriter) WriteBool(b bool) {
if b { if b {
i = 1 i = 1
} }
w.WriteByte(i) w.WriteB(i)
} }
// WriteArray writes a slice or an array arr into w. Note that nil slices and // WriteArray writes a slice or an array arr into w. Note that nil slices and
@ -123,22 +123,22 @@ func (w *BinWriter) WriteVarUint(val uint64) {
} }
if val < 0xfd { if val < 0xfd {
w.WriteByte(byte(val)) w.WriteB(byte(val))
return return
} }
if val < 0xFFFF { if val < 0xFFFF {
w.WriteByte(byte(0xfd)) w.WriteB(byte(0xfd))
w.WriteU16LE(uint16(val)) w.WriteU16LE(uint16(val))
return return
} }
if val < 0xFFFFFFFF { if val < 0xFFFFFFFF {
w.WriteByte(byte(0xfe)) w.WriteB(byte(0xfe))
w.WriteU32LE(uint32(val)) w.WriteU32LE(uint32(val))
return return
} }
w.WriteByte(byte(0xff)) w.WriteB(byte(0xff))
w.WriteU64LE(val) w.WriteU64LE(val)
} }

View file

@ -128,12 +128,12 @@ func TestWriteByte(t *testing.T) {
bin = []byte{0xa5} bin = []byte{0xa5}
) )
bw := NewBufBinWriter() bw := NewBufBinWriter()
bw.WriteByte(val) bw.WriteB(val)
assert.Nil(t, bw.Err) assert.Nil(t, bw.Err)
wrotebin := bw.Bytes() wrotebin := bw.Bytes()
assert.Equal(t, wrotebin, bin) assert.Equal(t, wrotebin, bin)
br := NewBinReaderFromBuf(bin) br := NewBinReaderFromBuf(bin)
readval = br.ReadByte() readval = br.ReadB()
assert.Nil(t, br.Err) assert.Nil(t, br.Err)
assert.Equal(t, val, readval) assert.Equal(t, val, readval)
} }
@ -165,7 +165,7 @@ func TestReadLEErrors(t *testing.T) {
assert.Equal(t, uint32(0), br.ReadU32LE()) assert.Equal(t, uint32(0), br.ReadU32LE())
assert.Equal(t, uint16(0), br.ReadU16LE()) assert.Equal(t, uint16(0), br.ReadU16LE())
assert.Equal(t, uint16(0), br.ReadU16BE()) assert.Equal(t, uint16(0), br.ReadU16BE())
assert.Equal(t, byte(0), br.ReadByte()) assert.Equal(t, byte(0), br.ReadB())
assert.Equal(t, false, br.ReadBool()) assert.Equal(t, false, br.ReadBool())
assert.NotNil(t, br.Err) assert.NotNil(t, br.Err)
} }

View file

@ -56,12 +56,12 @@ func NewInventory(typ InventoryType, hashes []util.Uint256) *Inventory {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (p *Inventory) DecodeBinary(br *io.BinReader) { func (p *Inventory) DecodeBinary(br *io.BinReader) {
p.Type = InventoryType(br.ReadByte()) p.Type = InventoryType(br.ReadB())
br.ReadArray(&p.Hashes) br.ReadArray(&p.Hashes)
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (p *Inventory) EncodeBinary(bw *io.BinWriter) { func (p *Inventory) EncodeBinary(bw *io.BinWriter) {
bw.WriteByte(byte(p.Type)) bw.WriteB(byte(p.Type))
bw.WriteArray(p.Hashes) bw.WriteArray(p.Hashes)
} }

View file

@ -22,7 +22,7 @@ func TestCreateMultiSigRedeemScript(t *testing.T) {
} }
br := io.NewBinReaderFromBuf(out) br := io.NewBinReaderFromBuf(out)
assert.Equal(t, opcode.PUSH3, opcode.Opcode(br.ReadByte())) assert.Equal(t, opcode.PUSH3, opcode.Opcode(br.ReadB()))
for i := 0; i < len(validators); i++ { for i := 0; i < len(validators); i++ {
bb := br.ReadVarBytes() bb := br.ReadVarBytes()
@ -32,6 +32,6 @@ func TestCreateMultiSigRedeemScript(t *testing.T) {
assert.Equal(t, validators[i].Bytes(), bb) assert.Equal(t, validators[i].Bytes(), bb)
} }
assert.Equal(t, opcode.PUSH3, opcode.Opcode(br.ReadByte())) assert.Equal(t, opcode.PUSH3, opcode.Opcode(br.ReadB()))
assert.Equal(t, opcode.CHECKMULTISIG, opcode.Opcode(br.ReadByte())) assert.Equal(t, opcode.CHECKMULTISIG, opcode.Opcode(br.ReadB()))
} }

View file

@ -80,12 +80,12 @@ func (pt ParamType) MarshalJSON() ([]byte, error) {
// EncodeBinary implements io.Serializable interface. // EncodeBinary implements io.Serializable interface.
func (pt ParamType) EncodeBinary(w *io.BinWriter) { func (pt ParamType) EncodeBinary(w *io.BinWriter) {
w.WriteByte(byte(pt)) w.WriteB(byte(pt))
} }
// DecodeBinary implements io.Serializable interface. // DecodeBinary implements io.Serializable interface.
func (pt *ParamType) DecodeBinary(r *io.BinReader) { func (pt *ParamType) DecodeBinary(r *io.BinReader) {
*pt = ParamType(r.ReadByte()) *pt = ParamType(r.ReadB())
} }
// NewParameter returns a Parameter with proper initialized Value // NewParameter returns a Parameter with proper initialized Value

View file

@ -50,14 +50,14 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) {
} }
r := io.NewBinReaderFromBuf(c.prog[c.ip:]) r := io.NewBinReaderFromBuf(c.prog[c.ip:])
var instrbyte = r.ReadByte() var instrbyte = r.ReadB()
instr := opcode.Opcode(instrbyte) instr := opcode.Opcode(instrbyte)
c.nextip++ c.nextip++
var numtoread int var numtoread int
switch instr { switch instr {
case opcode.PUSHDATA1, opcode.SYSCALL: case opcode.PUSHDATA1, opcode.SYSCALL:
var n = r.ReadByte() var n = r.ReadB()
numtoread = int(n) numtoread = int(n)
c.nextip++ c.nextip++
case opcode.PUSHDATA2: case opcode.PUSHDATA2:

View file

@ -94,7 +94,7 @@ func deserializeItem(data []byte) (StackItem, error) {
// as a function because StackItem itself is an interface. Caveat: always check // as a function because StackItem itself is an interface. Caveat: always check
// reader's error value before using the returned StackItem. // reader's error value before using the returned StackItem.
func DecodeBinaryStackItem(r *io.BinReader) StackItem { func DecodeBinaryStackItem(r *io.BinReader) StackItem {
var t = r.ReadByte() var t = r.ReadB()
if r.Err != nil { if r.Err != nil {
return nil return nil
} }