diff --git a/pkg/io/binaryReader.go b/pkg/io/binaryReader.go index b05846753..b2024f7bb 100644 --- a/pkg/io/binaryReader.go +++ b/pkg/io/binaryReader.go @@ -169,23 +169,16 @@ func (r *BinReader) ReadVarUint() uint64 { return 0 } - var b uint8 - r.Err = binary.Read(r.r, binary.LittleEndian, &b) + var b = r.ReadByte() if b == 0xfd { - var v uint16 - r.Err = binary.Read(r.r, binary.LittleEndian, &v) - return uint64(v) + return uint64(r.ReadU16LE()) } if b == 0xfe { - var v uint32 - r.Err = binary.Read(r.r, binary.LittleEndian, &v) - return uint64(v) + return uint64(r.ReadU32LE()) } if b == 0xff { - var v uint64 - r.Err = binary.Read(r.r, binary.LittleEndian, &v) - return v + return r.ReadU64LE() } return uint64(b) diff --git a/pkg/io/binaryWriter.go b/pkg/io/binaryWriter.go index 668b1b875..071b12119 100644 --- a/pkg/io/binaryWriter.go +++ b/pkg/io/binaryWriter.go @@ -123,24 +123,23 @@ func (w *BinWriter) WriteVarUint(val uint64) { } if val < 0xfd { - w.Err = binary.Write(w.w, binary.LittleEndian, uint8(val)) + w.WriteByte(byte(val)) return } if val < 0xFFFF { - w.Err = binary.Write(w.w, binary.LittleEndian, byte(0xfd)) - w.Err = binary.Write(w.w, binary.LittleEndian, uint16(val)) + w.WriteByte(byte(0xfd)) + w.WriteU16LE(uint16(val)) return } if val < 0xFFFFFFFF { - w.Err = binary.Write(w.w, binary.LittleEndian, byte(0xfe)) - w.Err = binary.Write(w.w, binary.LittleEndian, uint32(val)) + w.WriteByte(byte(0xfe)) + w.WriteU32LE(uint32(val)) return } - w.Err = binary.Write(w.w, binary.LittleEndian, byte(0xff)) - w.Err = binary.Write(w.w, binary.LittleEndian, val) - + w.WriteByte(byte(0xff)) + w.WriteU64LE(val) } // WriteBytes writes a variable byte into the underlying io.Writer without prefix.