Skip to main content

BitReader

A class in Alta.Serialization.Runtime, Alta.Serialization.

Reads values bit by bit from a buffer of 32 bit words, the reading half of the game's network and save serialization. Used by Stream on both sides.

Constructors​

MemberWhat it is
BitReader()Creates a BitReader with default values.

Fields​

7 private and internal fields
MemberWhat it is
private int bitIndexBit position inside the current word.
private int extraBytesBytes used in the last, partial word.
private Func<uint[], uint[]> getMoreDataCallback that returns the next buffer when reading runs past the current one.
private uint lastWordIndex of the last word holding data.
private static readonly Logger LoggerClass logger, used for buffer overrun and init errors.
private ulong scratch64 bit working value that holds the bits being read.
private uint wordIndexIndex of the word currently being read.

Properties​

MemberWhat it is
uint BitsRead { get; private set; }Bits read since the last Initialize or Reset.
uint[] Data { get; private set; }The word buffer being read. Can be swapped for a new one by the getMoreData callback.
uint TotalBits { get; private set; }Bits of real data in the buffer, from the byte count given to Initialize.

Methods​

MemberWhat it is
void Align()Skips bits up to the next byte boundary.
void BackTrack(uint bitCount)Moves the read position back by a number of bits.
void Clear()Drops the reference to the data buffer.
void Initialize(Func<uint[], uint[]> getMoreData, int byteCount)Starts reading a buffer holding a given number of bytes. The callback overload fetches more words when the buffer runs out.
void Initialize(uint[] data, int byteCount)Starts reading a buffer holding a given number of bytes. The callback overload fetches more words when the buffer runs out.
static uint NetworkToHost(uint value)Byte swap for word order. Leaves the value as is on little endian machines, so the wire order is little endian words.
uint ReadBits(int readCount)Reads up to 32 bits and returns them as a uint. Logs an error and wraps to the start if it reads past the buffer with no callback.
void ReadBytes(byte[] bytes, int byteCount)Reads a number of bytes into an array, copying whole words directly when aligned.
void Reset()Goes back to the start of the current buffer and drops the more data callback.
2 private and internal methods
MemberWhat it is
internal BitReader Copy()Internal: makes an independent reader with a copy of the data and the same read position.
private void LoadData()Loads the current word into the scratch value, shifting a partial last word into place.

Used in​

Members of other types that take, return or hold a BitReader: