Writes values of any width from 0 to 64 bits into a growing byte buffer.
More...
#include <aegis2d/net/bits.hpp>
|
| void | write_bits (std::uint64_t value, unsigned width) |
| | Appends an unsigned value.
|
| |
| void | write_signed (std::int64_t value, unsigned width) |
| | Appends a signed value in two's complement.
|
| |
| void | write_bool (bool value) |
| | Appends a boolean as one bit.
|
| |
| std::span< const std::byte > | data () const noexcept |
| | Bytes written so far, the last one completed with 0 bits.
|
| |
| std::size_t | size () const noexcept |
| | Number of bytes written so far, the last one counted even when incomplete.
|
| |
| std::size_t | bit_size () const noexcept |
| | Number of bits written so far.
|
| |
| void | clear () noexcept |
| | Empties the buffer and keeps its memory, to write the next payload.
|
| |
|
| static constexpr unsigned | max_width = 64 |
| | Widest value a single write accepts, in bits.
|
| |
Writes values of any width from 0 to 64 bits into a growing byte buffer.
Bits are packed from the least significant bit of each byte, in the order of the writes: bit n of the stream is bit n % 8 of byte n / 8, whatever the machine. The unused bits of the last byte are 0.
◆ bit_size()
| std::size_t aegis2d::net::BitWriter::bit_size |
( |
| ) |
const |
|
noexcept |
Number of bits written so far.
- Returns
- The offset of the next write, in bits.
◆ clear()
| void aegis2d::net::BitWriter::clear |
( |
| ) |
|
|
noexcept |
Empties the buffer and keeps its memory, to write the next payload.
◆ data()
| std::span< const std::byte > aegis2d::net::BitWriter::data |
( |
| ) |
const |
|
noexcept |
Bytes written so far, the last one completed with 0 bits.
- Returns
- A view of the buffer, valid until the next write or clear().
◆ size()
| std::size_t aegis2d::net::BitWriter::size |
( |
| ) |
const |
|
noexcept |
Number of bytes written so far, the last one counted even when incomplete.
- Returns
- The size of data().
◆ write_bits()
| void aegis2d::net::BitWriter::write_bits |
( |
std::uint64_t |
value, |
|
|
unsigned |
width |
|
) |
| |
Appends an unsigned value.
- Parameters
-
| value | Value to write. |
| width | Number of bits, from 0 to max_width; 0 writes nothing. |
- Exceptions
-
| std::invalid_argument | if width is above max_width or value does not fit. |
◆ write_bool()
| void aegis2d::net::BitWriter::write_bool |
( |
bool |
value | ) |
|
Appends a boolean as one bit.
- Parameters
-
◆ write_signed()
| void aegis2d::net::BitWriter::write_signed |
( |
std::int64_t |
value, |
|
|
unsigned |
width |
|
) |
| |
Appends a signed value in two's complement.
- Parameters
-
| value | Value to write. |
| width | Number of bits, sign included, from 1 to max_width. |
- Exceptions
-
| std::invalid_argument | if width is out of range or value does not fit. |
◆ max_width
| constexpr unsigned aegis2d::net::BitWriter::max_width = 64 |
|
staticconstexpr |
Widest value a single write accepts, in bits.
The documentation for this class was generated from the following file: