28 #include "nrg_packet.h"
33 static const size_t MAX_BYTE_SHIFTS = 7;
49 bits |= 1 << (detail::MAX_BYTE_SHIFTS - count);
55 if(++count > detail::MAX_BYTE_SHIFTS)
flush();
61 for(
int i = 0; i < sz; ++i){
95 if(count == 0) p.
read8(bits);
96 bool b = bits & (1 << (detail::MAX_BYTE_SHIFTS - count));
97 count = (count + 1) & detail::MAX_BYTE_SHIFTS;
104 for(
int i = 0; i < sz; ++i){
void clear()
Resets the internal set of bits that have not yet been written.
Definition: nrg_bit_io.h:74
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
PacketWritable & write8(const uint8_t &v)
Write a uint8_t, automatically converting endianness.
void flush(void)
Finishes writing bits to the packet, and resets the internal state.
Definition: nrg_bit_io.h:67
void writeFunc(int sz, const T &fn)
Calls BitWriter::write using the bool return value from the function fn sz times. ...
Definition: nrg_bit_io.h:60
void write1()
Write a 1 bit.
Definition: nrg_bit_io.h:48
void write(bool b)
Write a 1 or 0 if b is true or false respectively.
Definition: nrg_bit_io.h:43
~BitWriter()
Destructor, which will call BitWriter::flush.
Definition: nrg_bit_io.h:79
BitReader(Packet &p)
Constructs a BitReader that will read from the Packet p.
Definition: nrg_bit_io.h:91
void write0()
Write a 0 bit.
Definition: nrg_bit_io.h:54
Reads a stream of bytes from a packet more easily.
Definition: nrg_bit_io.h:88
Common defines and includes used by all the other nrg header files.
Writes a stream of bytes to a packet more easily.
Definition: nrg_bit_io.h:37
void readFunc(int sz, const T &fn)
Calls BitReader::read sz times, calling fn with each result.
Definition: nrg_bit_io.h:103
bool read(void)
Reads a bit from the internal state and returns a bool representation of it.
Definition: nrg_bit_io.h:94
PacketReadable & read8(uint8_t &v)
Read a uint8_t, automatically converting endianness.
BitWriter(Packet &p)
Constructor a BitWriter that will read from the Packet p.
Definition: nrg_bit_io.h:40