This commit is contained in:
Andrey Gumirov
2024-01-08 02:39:45 +07:00
parent fdcba0b869
commit 606ce553ac
9 changed files with 1594 additions and 0 deletions

43
bitstream.h Normal file
View File

@ -0,0 +1,43 @@
#include <cstddef>
#ifndef BITSTREAM
#define BITSTREAM
class ibitstream
{
private:
// read bits from byte
int count;
// last byte from stream
uint8_t cache;
// Input stream
std::basic_istream<char> &is;
public:
ibitstream(std::basic_istream<char> &is) : count(-1), cache('\0'), is(is) {};
// Get n bits from stream; at most - 32
int getbits(size_t n);
};
class obitstream
{
private:
// written bits to byte
int count;
// last byte from stream
uint8_t cache;
std::basic_ostream<char> &os;
public:
obitstream(std::basic_ostream<char> &os) : count(0), cache(0), os(os) {};
// Get n bits from stream; at most - 32
void writebits(short bits, size_t n);
void flush();
};
#endif