mCRL2
|
A bitstream provides per bit writing of data to any stream (including stdout). More...
#include <bitstream.h>
Public Member Functions | |
obitstream (std::ostream &stream) | |
Provides the stream on which the write function operate. | |
~obitstream () | |
void | write_bits (std::size_t value, unsigned int num_of_bits) |
Write the num_of_bits least significant bits in descending order from value. | |
void | write_string (const std::string &string) |
Write the given string to the output stream. | |
void | write_integer (std::size_t value) |
Write the given value to the output stream. | |
Private Member Functions | |
void | flush () |
Flush the remaining bits in the buffer to the output stream. | |
void | write (const std::uint8_t *buffer, std::size_t size) |
Writes size bytes from the given buffer. | |
Private Attributes | |
std::ostream & | stream |
std::bitset< 128 > | write_buffer = 0 |
Buffer that is filled starting from bit 127 when writing. | |
unsigned int | bits_in_buffer = 0 |
how many bits in are used in the buffer. | |
std::uint8_t | integer_buffer [integer_encoding_size< std::size_t >()] |
Reserved space to store an n byte integer. | |
A bitstream provides per bit writing of data to any stream (including stdout).
Internally uses bitpacking and buffering for compact and efficient IO.
Definition at line 31 of file bitstream.h.
obitstream::obitstream | ( | std::ostream & | stream | ) |
Provides the stream on which the write function operate.
Definition at line 101 of file bitstream.cpp.
|
inline |
Definition at line 36 of file bitstream.h.
|
private |
Flush the remaining bits in the buffer to the output stream.
Note that this aligns it to the next byte, e.g. when bits_in_buffer is 6 then two zero bits are added redundantly.
Definition at line 234 of file bitstream.cpp.
|
private |
Writes size bytes from the given buffer.
Definition at line 247 of file bitstream.cpp.
void obitstream::write_bits | ( | std::size_t | value, |
unsigned int | num_of_bits | ||
) |
Write the num_of_bits least significant bits in descending order from value.
value | Variable that contains the bits. |
num_of_bits | Number of bits to write to the output stream. |
Definition at line 115 of file bitstream.cpp.
void obitstream::write_integer | ( | std::size_t | value | ) |
Write the given value to the output stream.
Uses most significant bit encoding.
Definition at line 156 of file bitstream.cpp.
void obitstream::write_string | ( | const std::string & | string | ) |
Write the given string to the output stream.
Encoded in bits using <length, string>
Definition at line 147 of file bitstream.cpp.
|
private |
how many bits in are used in the buffer.
Definition at line 64 of file bitstream.h.
|
private |
Reserved space to store an n byte integer.
Definition at line 66 of file bitstream.h.
|
private |
Definition at line 59 of file bitstream.h.
|
private |
Buffer that is filled starting from bit 127 when writing.
Definition at line 62 of file bitstream.h.