45 "Given index is no termination index" )
49 terminationIndex.
pos--;
54 terminationIndex.
bit--;
58 SetWord(terminationIndex, word );
59 return terminationIndex;
67 static int isLittleEndianEncoding= 0;
69 bool IsLittleEndianEncoding()
71 if( isLittleEndianEncoding == 0 )
77 "Platform not supported")
79 isLittleEndianEncoding= 2;
84 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
86 if( *bytes == 0x11 && *(bytes+1) == 0x22)
87 isLittleEndianEncoding= 1;
94 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
96 if( * bytes == 0x11 && *(bytes+1) == 0x22
97 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44 )
98 isLittleEndianEncoding= 1;
104 testWord= 0x8877665544332211u;
106 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
108 if( * bytes == 0x11 && *(bytes+1) == 0x22
109 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44
110 && *(bytes+4) == 0x55 && *(bytes+5) == 0x66
111 && *(bytes+6) == 0x77 && *(bytes+7) == 0x88 )
112 isLittleEndianEncoding= 1;
118 return (isLittleEndianEncoding == 1);
126 "Given start index is not algined. The easiest way to get an aligned "
127 "index is to terminate the buffer." )
129 if( IsLittleEndianEncoding())
132 const size_t end= endIndex.
pos + (endIndex.
bit != 0 );
133 for (
size_t pos= startIndex.
pos; pos < end; ++pos)
137 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
139 bytes[0]= word & 0xFF;
140 word>>= 8; bytes[1]= word & 0xFF;
144 word>>= 8; bytes[2]= word & 0xFF;
145 word>>= 8; bytes[3]= word & 0xFF;
150 word>>= 8; bytes[4]= word & 0xFF;
151 word>>= 8; bytes[5]= word & 0xFF;
152 word>>= 8; bytes[6]= word & 0xFF;
153 word>>= 8; bytes[7]= word & 0xFF;
160 if( IsLittleEndianEncoding())
163 size_t end= endIndex.
pos + (endIndex.
bit != 0 );
164 for (
size_t pos= startIndex.
pos; pos < end; ++pos)
168 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
222 if( val < (1<< 8) ) {
Write<10>( val << 2 ); }
223 else if( val < (1<<16) ) {
Write<18>(( val << 2) | 1u ); }
224 else if( val < (1<<24) ) {
Write<26>(( val << 2) | 2u ); }
232 if( val < uint64_t(1) << 8 ) {
Write<11>( int16_t (val) << 3 ); }
233 else if( val < uint64_t(1) << 16 ) {
Write<19>( ( uint32_t (val) << 3 ) | 1u); }
234 else if( val < uint64_t(1) << 24 ) {
Write<27>( ( uint32_t (val) << 3 ) | 2u); }
235 else if( val < uint64_t(1) << 32 ) {
Write<35>( ( val << 3 ) | 3u); }
236 else if( val < uint64_t(1) << 40 ) {
Write<43>( ( val << 3 ) | 4u); }
237 else if( val < uint64_t(1) << 48 ) {
Write<51>( ( val << 3 ) | 5u); }
238 else if( val < uint64_t(1) << 56 ) {
Write<59>( ( val << 3 ) | 6u); }
249 return uint8_t(result >> 1);
251 return uint8_t( result >> 1
259 return uint16_t(result >> 1);
261 return uint16_t( result >> 1
270 case 0:
return uint32_t(result >> 2);
282 case 0:
return uint64_t(result >> 3);
lang::ShiftOpRHS bit
Current bit index in the current word.
uinteger pos
Index of the current word to read/write.
TStorage GetWord(const Index &index) const
ALIB_API Index Terminate(Index writerIndex)
void SetWord(const Index &index, TStorage value)
ALIB_API Index Unterminate(Index terminationIndex)
ALIB_API void ToLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
ALIB_API void FromLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
BitBufferBase::Index GetIndex() const
ALIB_API uint16_t readUIntegral16()
ALIB_API uint32_t readUIntegral32()
ALIB_API uint64_t readUIntegral64()
ALIB_API uint8_t readUIntegral8()
Writes bits into a BitBufferBase.
ALIB_API void writeUIntegral(uint8_t val)
void Write(TIntegral value)
#define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW
#define ALIB_WARNINGS_RESTORE
#define ALIB_STATIC_ASSERT(CondVariable, Cond, Message)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_WARNINGS_IGNORE_INTEGER_OVERFLOW
constexpr int MSB(TIntegral value)