2 // the Most Significant Bit of byte is First
4 #ifndef __STREAM_MSBFDECODER_H
5 #define __STREAM_MSBFDECODER_H
7 #include "../../Common/Types.h"
8 #include "../IStream.h"
13 const int kNumBigValueBits
= 8 * 4;
14 const int kNumValueBytes
= 3;
15 const int kNumValueBits
= 8 * kNumValueBytes
;
17 const UInt32 kMask
= (1 << kNumValueBits
) - 1;
19 template<class TInByte
>
26 bool Create(UInt32 bufferSize
) { return m_Stream
.Create(bufferSize
); }
27 void SetStream(ISequentialInStream
*inStream
) { m_Stream
.SetStream(inStream
);}
28 void ReleaseStream() { m_Stream
.ReleaseStream();}
33 m_BitPos
= kNumBigValueBits
;
37 UInt64
GetProcessedSize() const
38 { return m_Stream
.GetProcessedSize() - (kNumBigValueBits
- m_BitPos
) / 8; }
39 UInt32
GetBitPosition() const { return (m_BitPos
& 7); }
43 for (;m_BitPos
>= 8; m_BitPos
-= 8)
44 m_Value
= (m_Value
<< 8) | m_Stream
.ReadByte();
47 UInt32
GetValue(UInt32 numBits
) const
49 // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
50 return ((m_Value
>> (8 - m_BitPos
)) & kMask
) >> (kNumValueBits
- numBits
);
53 void MovePos(UInt32 numBits
)
59 UInt32
ReadBits(UInt32 numBits
)
61 UInt32 res
= GetValue(numBits
);