diff --git a/pkg/io/binaryWriter.go b/pkg/io/binaryWriter.go index b5aee0d0c..16e9dfc77 100644 --- a/pkg/io/binaryWriter.go +++ b/pkg/io/binaryWriter.go @@ -95,13 +95,16 @@ func (w *BinWriter) WriteVarUint(val uint64) { // WriteBytes writes a variable byte into the underlying io.Writer without prefix. func (w *BinWriter) WriteBytes(b []byte) { - w.WriteLE(b) + if w.Err != nil { + return + } + _, w.Err = w.w.Write(b) } // WriteVarBytes writes a variable length byte array into the underlying io.Writer. func (w *BinWriter) WriteVarBytes(b []byte) { w.WriteVarUint(uint64(len(b))) - w.WriteLE(b) + w.WriteBytes(b) } // WriteString writes a variable length string into the underlying io.Writer. diff --git a/pkg/io/binaryrw_test.go b/pkg/io/binaryrw_test.go index 6a6278e1e..19a8c2a55 100644 --- a/pkg/io/binaryrw_test.go +++ b/pkg/io/binaryrw_test.go @@ -210,6 +210,11 @@ func TestWriteBytes(t *testing.T) { buf := bw.Bytes() assert.Equal(t, 4, len(buf)) assert.Equal(t, byte(0xde), buf[0]) + + bw = NewBufBinWriter() + bw.Err = errors.New("smth bad") + bw.WriteBytes(bin) + assert.Equal(t, 0, bw.Len()) } type testSerializable uint16