forked from TrueCloudLab/neoneo-go
Merge pull request #554 from nspcc-dev/fix/removeio
io: remove Read/Write LE/BE They were replaced with faster specialized versions earlier. The only obstacle on the way to removing them completely was dbft library, which is also updated in this PR.
This commit is contained in:
commit
170d020081
5 changed files with 18 additions and 88 deletions
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/go-redis/redis v6.10.2+incompatible
|
||||
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||
github.com/mr-tron/base58 v1.1.2
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191213082456-c81c7a796775
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/prometheus/client_golang v1.2.1
|
||||
|
|
3
go.sum
3
go.sum
|
@ -1,5 +1,6 @@
|
|||
github.com/CityOfZion/neo-go v0.62.1-pre.0.20191114145240-e740fbe708f8/go.mod h1:MJCkWUBhi9pn/CrYO1Q3P687y2KeahrOPS9BD9LDGb0=
|
||||
github.com/CityOfZion/neo-go v0.70.1-pre.0.20191209120015-fccb0085941e/go.mod h1:0enZl0az8xA6PVkwzEOwPWVJGqlt/GO4hA4kmQ5Xzig=
|
||||
github.com/CityOfZion/neo-go v0.70.1-pre.0.20191212173117-32ac01130d4c/go.mod h1:JtlHfeqLywZLswKIKFnAp+yzezY4Dji9qlfQKB2OD/I=
|
||||
github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo=
|
||||
github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
|
||||
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
|
||||
|
@ -93,6 +94,8 @@ github.com/nspcc-dev/dbft v0.0.0-20191205084618-dacb1a30c254 h1:A4OkQDQOSPsJF8qU
|
|||
github.com/nspcc-dev/dbft v0.0.0-20191205084618-dacb1a30c254/go.mod h1:w1Ln2aT+dBlPhLnuZhBV+DfPEdS2CHWWLp5JTScY3bw=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae h1:T5V1QANlNMKun0EPB3eqg2PTXG4rmLhzDyEiV63kdB0=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA51EGfb5GS/HOv7VdmngNRTssSeQ729dvGY=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191213082456-c81c7a796775 h1:iqRxuEBrT2QbSdgmvGCwgn+lnOKmx1L5EiVTcOXUYt8=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191213082456-c81c7a796775/go.mod h1:IyIyVYKfi41kAlGWqicz9G8Iyni71Resuhtd9Y5ujJM=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0 h1:ftN+59WqxSWz/RCgXYOfhmltOOqU+udsNQSvN6wkFck=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c=
|
||||
|
|
|
@ -38,15 +38,6 @@ func NewBinReaderFromBuf(b []byte) *BinReader {
|
|||
return NewBinReaderFromIO(r)
|
||||
}
|
||||
|
||||
// ReadLE reads from the underlying io.Reader
|
||||
// into the interface v in little-endian format.
|
||||
func (r *BinReader) ReadLE(v interface{}) {
|
||||
if r.Err != nil {
|
||||
return
|
||||
}
|
||||
r.Err = binary.Read(r.r, binary.LittleEndian, v)
|
||||
}
|
||||
|
||||
// ReadU64LE reads a little-endian encoded uint64 value from the underlying
|
||||
// io.Reader. On read failures it returns zero.
|
||||
func (r *BinReader) ReadU64LE() uint64 {
|
||||
|
@ -153,15 +144,6 @@ func (r *BinReader) ReadArray(t interface{}, maxSize ...int) {
|
|||
value.Elem().Set(arr)
|
||||
}
|
||||
|
||||
// ReadBE reads from the underlying io.Reader
|
||||
// into the interface v in big-endian format.
|
||||
func (r *BinReader) ReadBE(v interface{}) {
|
||||
if r.Err != nil {
|
||||
return
|
||||
}
|
||||
r.Err = binary.Read(r.r, binary.BigEndian, v)
|
||||
}
|
||||
|
||||
// ReadVarUint reads a variable-length-encoded integer from the
|
||||
// underlying reader.
|
||||
func (r *BinReader) ReadVarUint() uint64 {
|
||||
|
|
|
@ -27,22 +27,6 @@ func NewBinWriterFromIO(iow io.Writer) *BinWriter {
|
|||
return &BinWriter{w: iow, u64: u64, u32: u32, u16: u16, u8: u8}
|
||||
}
|
||||
|
||||
// WriteLE writes into the underlying io.Writer from an object v in little-endian format.
|
||||
func (w *BinWriter) WriteLE(v interface{}) {
|
||||
if w.Err != nil {
|
||||
return
|
||||
}
|
||||
w.Err = binary.Write(w.w, binary.LittleEndian, v)
|
||||
}
|
||||
|
||||
// WriteBE writes into the underlying io.Writer from an object v in big-endian format.
|
||||
func (w *BinWriter) WriteBE(v interface{}) {
|
||||
if w.Err != nil {
|
||||
return
|
||||
}
|
||||
w.Err = binary.Write(w.w, binary.BigEndian, v)
|
||||
}
|
||||
|
||||
// WriteU64LE writes an uint64 value into the underlying io.Writer in
|
||||
// little-endian format.
|
||||
func (w *BinWriter) WriteU64LE(u64 uint64) {
|
||||
|
|
|
@ -19,40 +19,6 @@ func (w *badRW) Read(p []byte) (int, error) {
|
|||
return w.Write(p)
|
||||
}
|
||||
|
||||
func TestWriteLE(t *testing.T) {
|
||||
var (
|
||||
val uint32 = 0xdeadbeef
|
||||
readval uint32
|
||||
bin = []byte{0xef, 0xbe, 0xad, 0xde}
|
||||
)
|
||||
bw := NewBufBinWriter()
|
||||
bw.WriteLE(val)
|
||||
assert.Nil(t, bw.Err)
|
||||
wrotebin := bw.Bytes()
|
||||
assert.Equal(t, wrotebin, bin)
|
||||
br := NewBinReaderFromBuf(bin)
|
||||
br.ReadLE(&readval)
|
||||
assert.Nil(t, br.Err)
|
||||
assert.Equal(t, val, readval)
|
||||
}
|
||||
|
||||
func TestWriteBE(t *testing.T) {
|
||||
var (
|
||||
val uint32 = 0xdeadbeef
|
||||
readval uint32
|
||||
bin = []byte{0xde, 0xad, 0xbe, 0xef}
|
||||
)
|
||||
bw := NewBufBinWriter()
|
||||
bw.WriteBE(val)
|
||||
assert.Nil(t, bw.Err)
|
||||
wrotebin := bw.Bytes()
|
||||
assert.Equal(t, wrotebin, bin)
|
||||
br := NewBinReaderFromBuf(bin)
|
||||
br.ReadBE(&readval)
|
||||
assert.Nil(t, br.Err)
|
||||
assert.Equal(t, val, readval)
|
||||
}
|
||||
|
||||
func TestWriteU64LE(t *testing.T) {
|
||||
var (
|
||||
val uint64 = 0xbadc0de15a11dead
|
||||
|
@ -173,18 +139,18 @@ func TestReadLEErrors(t *testing.T) {
|
|||
func TestBufBinWriter_Len(t *testing.T) {
|
||||
val := []byte{0xde}
|
||||
bw := NewBufBinWriter()
|
||||
bw.WriteLE(val)
|
||||
bw.WriteBytes(val)
|
||||
require.Equal(t, 1, bw.Len())
|
||||
}
|
||||
|
||||
func TestWriterErrHandling(t *testing.T) {
|
||||
var badio = &badRW{}
|
||||
bw := NewBinWriterFromIO(badio)
|
||||
bw.WriteLE(uint32(0))
|
||||
bw.WriteU32LE(uint32(0))
|
||||
assert.NotNil(t, bw.Err)
|
||||
// these should work (without panic), preserving the Err
|
||||
bw.WriteLE(uint32(0))
|
||||
bw.WriteBE(uint32(0))
|
||||
bw.WriteU32LE(uint32(0))
|
||||
bw.WriteU16BE(uint16(0))
|
||||
bw.WriteVarUint(0)
|
||||
bw.WriteVarBytes([]byte{0x55, 0xaa})
|
||||
bw.WriteString("neo")
|
||||
|
@ -193,19 +159,14 @@ func TestWriterErrHandling(t *testing.T) {
|
|||
|
||||
func TestReaderErrHandling(t *testing.T) {
|
||||
var (
|
||||
i uint32 = 0xdeadbeef
|
||||
iorig = i
|
||||
badio = &badRW{}
|
||||
badio = &badRW{}
|
||||
)
|
||||
br := NewBinReaderFromIO(badio)
|
||||
br.ReadLE(&i)
|
||||
br.ReadU32LE()
|
||||
assert.NotNil(t, br.Err)
|
||||
// i shouldn't change
|
||||
assert.Equal(t, i, iorig)
|
||||
// these should work (without panic), preserving the Err
|
||||
br.ReadLE(&i)
|
||||
br.ReadBE(&i)
|
||||
assert.Equal(t, i, iorig)
|
||||
br.ReadU32LE()
|
||||
br.ReadU16BE()
|
||||
val := br.ReadVarUint()
|
||||
assert.Equal(t, val, uint64(0))
|
||||
b := br.ReadVarBytes()
|
||||
|
@ -217,7 +178,7 @@ func TestReaderErrHandling(t *testing.T) {
|
|||
|
||||
func TestBufBinWriterErr(t *testing.T) {
|
||||
bw := NewBufBinWriter()
|
||||
bw.WriteLE(uint32(0))
|
||||
bw.WriteU32LE(uint32(0))
|
||||
assert.Nil(t, bw.Err)
|
||||
// inject error
|
||||
bw.Err = errors.New("oopsie")
|
||||
|
@ -229,7 +190,7 @@ func TestBufBinWriterErr(t *testing.T) {
|
|||
func TestBufBinWriterReset(t *testing.T) {
|
||||
bw := NewBufBinWriter()
|
||||
for i := 0; i < 3; i++ {
|
||||
bw.WriteLE(uint32(i))
|
||||
bw.WriteU32LE(uint32(i))
|
||||
assert.Nil(t, bw.Err)
|
||||
_ = bw.Bytes()
|
||||
assert.NotNil(t, bw.Err)
|
||||
|
@ -338,24 +299,24 @@ type testSerializable uint16
|
|||
|
||||
// EncodeBinary implements io.Serializable interface.
|
||||
func (t testSerializable) EncodeBinary(w *BinWriter) {
|
||||
w.WriteLE(t)
|
||||
w.WriteU16LE(uint16(t))
|
||||
}
|
||||
|
||||
// DecodeBinary implements io.Serializable interface.
|
||||
func (t *testSerializable) DecodeBinary(r *BinReader) {
|
||||
r.ReadLE(t)
|
||||
*t = testSerializable(r.ReadU16LE())
|
||||
}
|
||||
|
||||
type testPtrSerializable uint16
|
||||
|
||||
// EncodeBinary implements io.Serializable interface.
|
||||
func (t *testPtrSerializable) EncodeBinary(w *BinWriter) {
|
||||
w.WriteLE(t)
|
||||
w.WriteU16LE(uint16(*t))
|
||||
}
|
||||
|
||||
// DecodeBinary implements io.Serializable interface.
|
||||
func (t *testPtrSerializable) DecodeBinary(r *BinReader) {
|
||||
r.ReadLE(t)
|
||||
*t = testPtrSerializable(r.ReadU16LE())
|
||||
}
|
||||
|
||||
func TestBinWriter_WriteArray(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue