consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "Buffer.hpp"
|
||||
|
||||
class BitWriter
|
||||
{
|
||||
public:
|
||||
int k = 0;
|
||||
Buffer buffer;
|
||||
char x = 0;
|
||||
|
||||
void writeByte(uint8_t x)
|
||||
{
|
||||
// f.write((char*)&x, 1);
|
||||
buffer.add_end(&x, sizeof(uint8_t));
|
||||
}
|
||||
|
||||
void writeInt(int x)
|
||||
{
|
||||
buffer.add_end((uint8_t *)&x, sizeof(x));
|
||||
}
|
||||
|
||||
void writeBit(bool b)
|
||||
{
|
||||
if (k == 8)
|
||||
{
|
||||
writeByte(x);
|
||||
k = 0;
|
||||
x = 0;
|
||||
}
|
||||
x ^= (-b ^ x) & (1 << k);
|
||||
k++;
|
||||
}
|
||||
|
||||
void finish()
|
||||
{
|
||||
if (k > 0)
|
||||
writeByte(x);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user