Skip to main content

Struct BitReader

Helper class for doing bitwise reads for a FastBufferReader. Ensures all bitwise reads end on proper byte alignment so FastBufferReader doesn't have to be concerned with misaligned reads.

Inherited Members

System.ValueType.Equals(System.Object)

System.ValueType.GetHashCode()

System.ValueType.ToString()

System.Object.Equals(System.Object, System.Object)

System.Object.GetType()

System.Object.ReferenceEquals(System.Object, System.Object)

Namespace: Unity.Netcode
Assembly: MLAPI.dll
Syntax
public ref struct BitReader

Properties

BitAligned

Whether or not the current BitPosition is evenly divisible by 8. I.e. whether or not the BitPosition is at a byte boundary.

Declaration
public readonly bool BitAligned { get; }
Property Value
TypeDescription
System.Boolean

Methods

Dispose()

Pads the read bit count to byte alignment and commits the read back to the reader

Declaration
public void Dispose()

ReadBit(out Boolean)

Read a single bit from the buffer

Declaration
public void ReadBit(out bool bit)
Parameters
TypeNameDescription
System.BooleanbitOut value of the bit. True represents 1, False represents 0

ReadBits(out Byte, UInt32)

Read bits from stream.

Declaration
public void ReadBits(out byte value, uint bitCount)
Parameters
TypeNameDescription
System.BytevalueValue to store bits into.
System.UInt32bitCountAmount of bits to read.

ReadBits(out UInt64, UInt32)

Read a certain amount of bits from the stream.

Declaration
public void ReadBits(out ulong value, uint bitCount)
Parameters
TypeNameDescription
System.UInt64valueValue to store bits into.
System.UInt32bitCountAmount of bits to read

TryBeginReadBits(UInt32)

Verifies the requested bit count can be read from the buffer. This exists as a separate method to allow multiple bit reads to be bounds checked with a single call. If it returns false, you may not read, and in editor and development builds, attempting to do so will throw an exception. In release builds, attempting to do so will read junk memory.

Declaration
public bool TryBeginReadBits(uint bitCount)
Parameters
TypeNameDescription
System.UInt32bitCountNumber of bits you want to read, in total
Returns
TypeDescription
System.BooleanTrue if you can read, false if that would exceed buffer bounds