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
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.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 bool BitAligned { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Dispose()
Pads the read bit count to byte alignment and commits the read back to the reader
Declaration
public void Dispose()
ReadBit(out bool)
Read a single bit from the buffer
Declaration
public void ReadBit(out bool bit)
Parameters
Type | Name | Description |
---|---|---|
bool | bit | Out value of the bit. True represents 1, False represents 0 |
ReadBits(out byte, uint)
Read bits from stream.
Declaration
public void ReadBits(out byte value, uint bitCount)
Parameters
Type | Name | Description |
---|---|---|
byte | value | Value to store bits into. |
uint | bitCount | Amount of bits to read. |
ReadBits(out ulong, uint)
Read a certain amount of bits from the stream.
Declaration
public void ReadBits(out ulong value, uint bitCount)
Parameters
Type | Name | Description |
---|---|---|
ulong | value | Value to store bits into. |
uint | bitCount | Amount of bits to read |
TryBeginReadBits(uint)
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
Type | Name | Description |
---|---|---|
uint | bitCount | Number of bits you want to read, in total |
Returns
Type | Description |
---|---|
bool | True if you can read, false if that would exceed buffer bounds |