![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Packs values to the bit into a byte buffer. More...
#include <bit_stream.h>
Public Member Functions | |
| BitWriter (std::vector< uint8_t > &bytes, size_t capacity) | |
Write into bytes, filling at most capacity of them. | |
| void | bits (uint32_t value, uint32_t width) |
Write the low width bits of value. | |
| void | u64 (uint64_t value) |
| Two words, high first, because the field width is capped at 32. | |
| void | f32 (float value) |
| A float as its exact bits, for the values quantisation would spoil. | |
| void | append (const uint8_t *bytes, size_t count) |
Write count bits from bytes, starting at its first bit. | |
| size_t | bitCount () const |
| Bits written so far. | |
| size_t | byteCount () const |
| Whole bytes needed to carry what has been written. | |
| bool | overflowed () const |
| True when a write did not fit. | |
| void | finish () |
| Flush the last partial byte into the buffer. | |
Packs values to the bit into a byte buffer.
A field costs what it needs, not its type's size: a flag is one bit.
Bounded by the packet's size: a write past it sets a sticky overflow flag instead of growing, so a caller asks once whether it all fit. Bits gather in a 64-bit word; the last partial byte stays there until finish().
|
inline |
Write into bytes, filling at most capacity of them.
| bytes | Buffer to fill; emptied, then grown as bytes complete. Holds the whole stream only after finish(). |
| capacity | The packet's ceiling, in bytes. |
|
inline |
Write the low width bits of value.
| value | Value to write; bits above width are ignored. |
| width | 1 to 32. |
|
inline |
Write count bits from bytes, starting at its first bit.
For splicing something already encoded, which is not a whole number of bytes.
| bytes | Buffer holding the encoded bits, first bit first. |
| count | Bits to take from it. |
|
inline |
True when a write did not fit.
Sticky, so a caller tests once at the end.