diff --git a/d2common/d2datautils/stream_writer.go b/d2common/d2datautils/stream_writer.go index 98de3746..57a2a90e 100644 --- a/d2common/d2datautils/stream_writer.go +++ b/d2common/d2datautils/stream_writer.go @@ -34,7 +34,7 @@ func (v *StreamWriter) PushBytes(b ...byte) { } // PushBit pushes single bit into stream -// WARNING: if you'll use PushBit, offset'll be less then 7, and if you'll +// WARNING: if you'll use PushBit, offset'll be less than 8, and if you'll // use another Push... method, bits'll not be pushed func (v *StreamWriter) PushBit(b bool) { if b { @@ -54,17 +54,12 @@ func (v *StreamWriter) PushBit(b bool) { // PushBits pushes bits (with max range 8) func (v *StreamWriter) PushBits(b byte, bits int) { if bits > bitsPerByte { - log.Print("input bits number must be less (or equal) then 8") + log.Print("input bits number must be less (or equal) than 8") } val := b for i := 0; i < bits; i++ { - if val&1 == 1 { - v.PushBit(true) - } else { - v.PushBit(false) - } - + v.PushBit(val&1 == 1) val >>= 1 } } @@ -72,17 +67,12 @@ func (v *StreamWriter) PushBits(b byte, bits int) { // PushBits16 pushes bits (with max range 16) func (v *StreamWriter) PushBits16(b uint16, bits int) { if bits > bitsPerByte*bytesPerint16 { - log.Print("input bits number must be less (or equal) then 16") + log.Print("input bits number must be less (or equal) than 16") } val := b for i := 0; i < bits; i++ { - if val&1 == 1 { - v.PushBit(true) - } else { - v.PushBit(false) - } - + v.PushBit(val&1 == 1) val >>= 1 } } @@ -90,17 +80,12 @@ func (v *StreamWriter) PushBits16(b uint16, bits int) { // PushBits32 pushes bits (with max range 32) func (v *StreamWriter) PushBits32(b uint32, bits int) { if bits > bitsPerByte*bytesPerint32 { - log.Print("input bits number must be less (or equal) then 32") + log.Print("input bits number must be less (or equal) than 32") } val := b for i := 0; i < bits; i++ { - if val&1 == 1 { - v.PushBit(true) - } else { - v.PushBit(false) - } - + v.PushBit(val&1 == 1) val >>= 1 } } diff --git a/d2common/d2datautils/stream_writer_test.go b/d2common/d2datautils/stream_writer_test.go index cc199739..68c22cda 100644 --- a/d2common/d2datautils/stream_writer_test.go +++ b/d2common/d2datautils/stream_writer_test.go @@ -31,7 +31,9 @@ func TestStreamWriterBits16(t *testing.T) { output := sr.GetBytes() for i, d := range data { - outputInt := uint16(output[bytesPerint16*i]) | uint16(output[bytesPerint16*i+1])<<8 + // nolint:gomnd // offset in byte slice; bit shifts for uint16 + outputInt := uint16(output[bytesPerint16*i]) | + uint16(output[bytesPerint16*i+1])<<8 if outputInt != d { t.Fatalf("sr.PushBits16() pushed %X, but wrote %X instead", d, output[i]) } @@ -49,6 +51,7 @@ func TestStreamWriterBits32(t *testing.T) { output := sr.GetBytes() for i, d := range data { + // nolint:gomnd // offset in byte slice; bit shifts for uint32 outputInt := uint32(output[bytesPerint32*i]) | uint32(output[bytesPerint32*i+1])<<8 | uint32(output[bytesPerint32*i+2])<<16 |