Writes bits into a BitBufferBase.
Definition at line 666 of file bitbuffer.hpp.
#include <bitbuffer.hpp>
◆ TStorage
◆ word
The current word, which is partly written and not stored in buffer, yet.
Definition at line 672 of file bitbuffer.hpp.
◆ BitWriter() [1/2]
Constructs a bit writer operating on the given bit buffer.
- Parameters
-
buffer | The buffer to write to (starting at the beginning). |
Definition at line 677 of file bitbuffer.hpp.
◆ BitWriter() [2/2]
Constructs a bit writer operating on the given bit buffer, starting to write at the given Index.
- Parameters
-
buffer | The buffer to write to. |
index | An index providing the postion of the first bit to (over-) write in buffer . |
Definition at line 688 of file bitbuffer.hpp.
◆ ~BitWriter()
◆ Flush()
Writes the last word of bits into the underlying buffer. This method has to be called before writing the buffer to a file or similar. The method is automatically invoked on destruction.
Definition at line 720 of file bitbuffer.hpp.
◆ Reset() [1/2]
Resets the internal index of this writer to the start of the bit buffer.
Definition at line 702 of file bitbuffer.hpp.
◆ Reset() [2/2]
Resets the internal index of this writer to the given one.
- Parameters
-
index | The position of the next bit in the buffer to write to. |
Definition at line 710 of file bitbuffer.hpp.
◆ Write() [1/3]
template<typename TValue , bool TMaskValue = false>
Writes the given integral value with the given number of bits to the stream.
- Note
- Internally, different template functions selected with
std::enable_if
for different integral types.
- See also
- A method that uses a template parameter for the number of bits to write, is is available with Write<TWidth,TIntegral>(TIntegral). This might be slightly faster and should be used instead of this method, whenever the number of bits to write is known at compilation time.
- Template Parameters
-
TValue | The integral type of the value to write. (Deduced from parameter value .) |
TMaskValue | Determines if bits beyond width of given value may be set and have to be masked out. Defaults to false . |
- Parameters
-
width | The number of bits in value . |
value | The value to write. |
◆ Write() [2/3]
template<
ShiftOpRHS TWidth, typename TIntegral , bool TMaskValue = false>
void Write |
( |
TIntegral | value | ) |
|
Writes the given integral value with the given number of bits to the stream.
- Note
- Internally, different template functions selected with
std::enable_if
for the different integral types.
- See also
- This method uses a template parameter for the number of bits to write. A slightly slower, non-templated version is available with Write<TValue, TMaskValue>( ShiftOpRHS, TValue) which is to be used when the value is determined only at run-time.
- Template Parameters
-
TWidth | The number of bits in value to write. |
TValue | The type of value to write. (Deduced from parameter value .) |
TMaskValue | Determines if bits beyond width of given value may be set and have to be masked out. Defaults to false . |
- Parameters
-
◆ Write() [3/3]
template<typename TIntegral >
void Write |
( |
TIntegral | value | ) |
|
Writes the given integral value to the stream by writing lower values with smaller sizes, due to the general assumption that lower values are more frequent and the average written size is less than the full size, despite the overhead needed to write information about how a value is encoded.
The endcoding for unsigned integrals is as follows:
- For byte value type, a single bit
'0'
is written if the value is below 8
, followed by the 3 bits containing the value. Otherwise, a single bit '1'
is written, followed by the full 8 bits.
- For all other value types (16-, 32- and 64-bit) the number of bytes needed is written first (one bit in the case of 16-bit values, two bits in the case of 32 bit values and three bits in the case of 64 bit values) and then the corresponding number of full bytes are written.
Signed integrals are converted to unsigned integrals using the sometimes called "zig-zag coding". Here, all numbers are doubled and negative numbers are turned positive and uneven. This way, the least significant bit becomes the sign bit. The advantage of this approach is of course that small numbers, negative or positive, remain small in respect to their bitwise representation.
The converstion hence is as follows: unsigned = signed >= 0 ? signed * 2 : ( (-signed -1 ) * 2 ) | 1
- Parameters
-
◆ writeUIntegral() [1/4]
void writeUIntegral |
( |
uint16_t | val | ) |
|
|
protected |
Internal method that writes a unsigned 16-bit value.
- Parameters
-
Definition at line 208 of file bitbuffer.cpp.
◆ writeUIntegral() [2/4]
void writeUIntegral |
( |
uint32_t | val | ) |
|
|
protected |
Internal method that writes a unsigned 32-bit value.
- Parameters
-
Definition at line 220 of file bitbuffer.cpp.
◆ writeUIntegral() [3/4]
void writeUIntegral |
( |
uint64_t | val | ) |
|
|
protected |
Internal method that writes a unsigned 64-bit value.
- Parameters
-
Definition at line 230 of file bitbuffer.cpp.
◆ writeUIntegral() [4/4]
void writeUIntegral |
( |
uint8_t | val | ) |
|
|
protected |
Internal method that writes a unsigned 8-bit value.
- Parameters
-
Definition at line 196 of file bitbuffer.cpp.
The documentation for this class was generated from the following files: