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
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
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
Boolean | bit | Out 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
Type | Name | Description |
---|---|---|
Byte | value | Value to store bits into. |
UInt32 | bitCount | Amount 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
Type | Name | Description |
---|---|---|
UInt64 | value | Value to store bits into. |
UInt32 | bitCount | Amount 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
Type | Name | Description |
---|---|---|
UInt32 | bitCount | Number of bits you want to read, in total |
Returns
Type | Description |
---|---|
Boolean | True if you can read, false if that would exceed buffer bounds |