Inherits reference_wrapper< Stream >.
template<typename Stream, typename Block>
class framework::serializable::bit_stream< Stream, Block >
Bit stream.
Provides bit-level access to the underlying stream. Blocks of data are serialized according to the provided Block
specification - each block's bits are consumed from the most to the least significant bit. This wrapper provides traditional byte-level read/write methods with each byte consuming the next CHAR_BIT
bits in the stream, and type-sensitive read_bits/write_bits methods which read a fixed number of bits into the provided container.
Note that the interpretation of a byte-level method is dependent on the definition of the Block
type - streams should generally use big endian byte ordering here to avoid altering the implicit definition of underlying types. For example, consider the following field definitions:
using field = value <
NAME(
"Field 1"), big_endian <uint32_t>>;
using ex1 = alias <bit_field <big_endian <uint16_t>, field>>;
using ex2 = alias <bit_field <little_endian <uint16_t>, field>>;
In the first example, ex1
, the definition of field
is unaltered - a byte-sequence (a,b,c,d) is read into Field 1 as 0xabcd, as expected. In the second example, on the other hand, a byte sequence (a,b,c,d) is effectively interpreted as 0xbadc - that is, using PDP-11 byte ordering.
- Warning
- The final operation following a series of writes to a bit stream should be a call to flush to ensure any remaining bits in the buffer are written to the underlying stream. Any unused bits in the data block are set to zero.
- Template Parameters
-
Stream | stream type |
Block | block type |