init initializes and resets the bit reader.
(in []byte)
| 134 | |
| 135 | // init initializes and resets the bit reader. |
| 136 | func (b *bitReaderShifted) init(in []byte) error { |
| 137 | if len(in) < 1 { |
| 138 | return errors.New("corrupt stream: too short") |
| 139 | } |
| 140 | b.in = in |
| 141 | b.off = uint(len(in)) |
| 142 | // The highest bit of the last byte indicates where to start |
| 143 | v := in[len(in)-1] |
| 144 | if v == 0 { |
| 145 | return errors.New("corrupt stream, did not find end of stream") |
| 146 | } |
| 147 | b.bitsRead = 64 |
| 148 | b.value = 0 |
| 149 | if len(in) >= 8 { |
| 150 | b.fillFastStart() |
| 151 | } else { |
| 152 | b.fill() |
| 153 | b.fill() |
| 154 | } |
| 155 | b.advance(8 - uint8(highBit32(uint32(v)))) |
| 156 | return nil |
| 157 | } |
| 158 | |
| 159 | // peekBitsFast requires that at least one bit is requested every time. |
| 160 | // There are no checks if the buffer is filled. |
no test coverage detected