32 && terminationIndex.
bit == 0
33 &&
data[terminationIndex.
pos - 1] != 0,
34 "BITBUFFER",
"Given index is no termination index" )
37 terminationIndex.
pos--;
42 terminationIndex.
bit--;
46 SetWord(terminationIndex, word );
47 return terminationIndex;
55 static int isLittleEndianEncoding= 0;
57bool IsLittleEndianEncoding() {
58 if( isLittleEndianEncoding == 0 ) {
63 "Platform not supported")
65 isLittleEndianEncoding= 2;
68 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
69 if( *bytes == 0x11 && *(bytes+1) == 0x22)
70 isLittleEndianEncoding= 1;
75 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
76 if( * bytes == 0x11 && *(bytes+1) == 0x22
77 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44 )
78 isLittleEndianEncoding= 1;
83 testWord= 0x8877665544332211u;
84 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
85 if( * bytes == 0x11 && *(bytes+1) == 0x22
86 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44
87 && *(bytes+4) == 0x55 && *(bytes+5) == 0x66
88 && *(bytes+6) == 0x77 && *(bytes+7) == 0x88 )
89 isLittleEndianEncoding= 1;
94 return (isLittleEndianEncoding == 1);
101 "Given start index is not algined. The easiest way to get an aligned "
102 "index is to terminate the buffer." )
104 if( IsLittleEndianEncoding())
107 const size_t end= endIndex.
pos + (endIndex.
bit != 0 );
108 for (
size_t pos= startIndex.
pos; pos < end; ++pos) {
110 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
111 bytes[0]= word & 0xFF;
112 word>>= 8; bytes[1]= word & 0xFF;
115 word>>= 8; bytes[2]= word & 0xFF;
116 word>>= 8; bytes[3]= word & 0xFF;
120 word>>= 8; bytes[4]= word & 0xFF;
121 word>>= 8; bytes[5]= word & 0xFF;
122 word>>= 8; bytes[6]= word & 0xFF;
123 word>>= 8; bytes[7]= word & 0xFF;
127 if( IsLittleEndianEncoding())
130 size_t end= endIndex.
pos + (endIndex.
bit != 0 );
131 for (
size_t pos= startIndex.
pos; pos < end; ++pos) {
133 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
179 else if( val < (1<<16) ) {
WriteBits<18>(( val << 2) | 1u ); }
180 else if( val < (1<<24) ) {
WriteBits<26>(( val << 2) | 2u ); }
187 if( val < uint64_t(1) << 8 ) {
WriteBits<11>( int16_t (val) << 3 ); }
188 else if( val < uint64_t(1) << 16 ) {
WriteBits<19>( ( uint32_t (val) << 3 ) | 1u); }
189 else if( val < uint64_t(1) << 24 ) {
WriteBits<27>( ( uint32_t (val) << 3 ) | 2u); }
190 else if( val < uint64_t(1) << 32 ) {
WriteBits<35>( ( val << 3 ) | 3u); }
191 else if( val < uint64_t(1) << 40 ) {
WriteBits<43>( ( val << 3 ) | 4u); }
192 else if( val < uint64_t(1) << 48 ) {
WriteBits<51>( ( val << 3 ) | 5u); }
193 else if( val < uint64_t(1) << 56 ) {
WriteBits<59>( ( val << 3 ) | 6u); }
203 return uint8_t(result >> 1);
205 return uint8_t( result >> 1
212 return uint16_t(result >> 1);
214 return uint16_t( result >> 1
220 switch (result & 3) {
221 case 0:
return uint32_t(result >> 2);
229 switch (result & 7) {
230 case 0:
return uint64_t(result >> 3);
#define ALIB_ALLOW_INTEGRAL_CONSTANT_OVERFLOW
#define ALIB_ALLOW_INTEGER_OVERFLOW
#define ALIB_STATIC_ASSERT(CondVariable, Cond, Message)
#define ALIB_POP_ALLOWANCE
#define ALIB_ASSERT_ERROR(cond, domain,...)
lang::ShiftOpRHS bit
Current bit index in the current word.
uinteger pos
Index of the current word to read/write.
Index Unterminate(Index terminationIndex)
void SetWord(const Index &index, TStorage value)
Index Terminate(Index writerIndex)
void ToLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
void FromLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
TStorage GetWord(const Index &index) const
BitBufferBase::Index GetIndex() const
uint64_t readUIntegral64()
uint32_t readUIntegral32()
uint16_t readUIntegral16()
Writes bits into a #"BitBufferBase".
void writeUIntegral(uint8_t value)
void WriteBits(TIntegral value)
constexpr int MSB(TIntegral value)