Represents a buffer for reading and writing bits. More...
Inherits INetBitWriteStream, and ILogDumpable.
Classes | |
struct | Offset |
Represents an offset within a NetBitBuffer. More... | |
Public Member Functions | |
bool | CanRead (int bits) |
Checks if the specified number of bits can be read from the buffer. More... | |
bool | CanWrite (int bits) |
Checks if the specified number of bits can be written to the buffer. More... | |
bool | CheckBitCount (int count) |
Checks if the specified number of bits can be read or written without exceeding the buffer length. More... | |
void | Clear () |
Clears the buffer by setting all bits to zero. More... | |
void ILogDumpable. | Dump (StringBuilder builder) |
byte * | GetDataPointer () |
Gets a pointer to the current data position in the buffer. More... | |
void | PadToByteBoundary () |
Pads the buffer to the next byte boundary by writing zero bits if necessary. More... | |
byte * | PadToByteBoundaryAndGetPtr () |
Pads the buffer to the next byte boundary and returns a pointer to the current data position. More... | |
ulong | Peek (int bits) |
bool | PeekBoolean () |
Peeks at the next boolean value in the buffer without advancing the read position. More... | |
ulong | Read (int bits) |
bool | ReadBoolean () |
Reads a boolean value from the buffer. More... | |
byte | ReadByte (int bits=8) |
Reads a byte value from the buffer. More... | |
void | ReadBytesAligned (byte[] buffer, int length) |
Reads an array of bytes from the buffer, ensuring byte alignment. More... | |
void | ReadBytesAligned (void *buffer, int length) |
Reads a block of bytes from the buffer, ensuring byte alignment. More... | |
double | ReadDouble () |
Reads a double-precision floating-point value from the buffer. More... | |
short | ReadInt16 (int bits=16) |
Reads a 16-bit signed integer value from the buffer. More... | |
int | ReadInt32 (int bits=32) |
Reads a 32-bit signed integer value from the buffer. More... | |
int | ReadInt32VarLength () |
Reads a 32-bit signed integer value with variable length from the buffer. More... | |
int | ReadInt32VarLength (int blockSize) |
Reads a 32-bit signed integer value with variable length from the buffer. More... | |
long | ReadInt64 (int bits=64) |
Reads a 64-bit signed integer value from the buffer. More... | |
long | ReadInt64VarLength (int blockSize) |
Reads a 64-bit signed integer value with variable length from the buffer. More... | |
float | ReadSingle () |
Reads a single-precision floating-point value from the buffer. More... | |
string | ReadString () |
Reads a string from the buffer using UTF-8 encoding. More... | |
string | ReadString (Encoding encoding) |
Reads a string from the buffer using the specified encoding. More... | |
ushort | ReadUInt16 (int bits=16) |
Reads a 16-bit unsigned integer value from the buffer. More... | |
uint | ReadUInt32 (int bits=32) |
Reads a 32-bit unsigned integer value from the buffer. More... | |
uint | ReadUInt32VarLength () |
Reads a 32-bit unsigned integer value with variable length from the buffer. More... | |
uint | ReadUInt32VarLength (int blockSize) |
Reads a 32-bit unsigned integer value with variable length from the buffer. More... | |
ulong | ReadUInt64 (int bits=64) |
Reads a 64-bit unsigned integer value from the buffer. More... | |
ulong | ReadUInt64VarLength (int blockSize) |
Reads a 64-bit unsigned integer value with variable length from the buffer. More... | |
void | ReplaceDataFromBlockWithTemp (int tempSize) |
Replaces the current data block with a temporary block of the specified size. More... | |
void | SeekToByteBoundary () |
Advances the buffer offset to the next byte boundary. More... | |
void | SetBufferLengthBytes (ulong *buffer, int lenghtInBytes) |
Sets the buffer length in bytes and updates the internal length in bits. More... | |
void | Write (ulong value, int bits) |
Writes a value to the buffer with a specified number of bits. More... | |
bool | WriteBoolean (bool value) |
Writes a boolean value to the buffer. More... | |
void | WriteByte (byte value, int bits=8) |
Writes a byte value to the buffer. More... | |
void | WriteBytesAligned (byte[] buffer, int length) |
Writes an array of bytes to the buffer, ensuring byte alignment. More... | |
void | WriteBytesAligned (void *buffer, int length) |
Writes a block of bytes to the buffer, ensuring byte alignment. More... | |
void | WriteDouble (double value) |
Writes a double-precision floating-point value to the buffer. More... | |
void | WriteInt16 (short value, int bits=16) |
Writes a 16-bit signed integer value to the buffer. More... | |
void | WriteInt32 (int value, int bits=32) |
Writes a 32-bit signed integer value to the buffer. More... | |
void | WriteInt32AtOffset (int value, int offset, int bits) |
Writes a 32-bit integer value at a specified offset in the buffer. More... | |
void | WriteInt32VarLength (int value) |
Writes a 32-bit signed integer value with variable length to the buffer. More... | |
void | WriteInt32VarLength (int value, int blockSize) |
Writes a 32-bit signed integer value with variable length to the buffer. More... | |
void | WriteInt64 (long value, int bits=64) |
Writes a 64-bit signed integer value to the buffer. More... | |
void | WriteInt64VarLength (long value, int blockSize) |
Writes a 64-bit signed integer value with variable length to the buffer. More... | |
void | WriteSingle (float value) |
Writes a single-precision floating-point value to the buffer. More... | |
void | WriteSlow (ulong value, int bits) |
Writes a value to the buffer with a specified number of bits, handling cases where the value spans multiple words. More... | |
void | WriteString (string value) |
Writes a string to the buffer using UTF-8 encoding. More... | |
void | WriteString (string value, Encoding encoding) |
Writes a string to the buffer using the specified encoding. More... | |
void | WriteUInt16 (ushort value, int bits=16) |
Writes a 16-bit unsigned integer value to the buffer. More... | |
void | WriteUInt32 (uint value, int bits=32) |
Writes a 32-bit unsigned integer value to the buffer. More... | |
void | WriteUInt32VarLength (uint value) |
Writes a 32-bit unsigned integer value with variable length to the buffer. More... | |
void | WriteUInt32VarLength (uint value, int blockSize) |
Writes a 32-bit unsigned integer value with variable length to the buffer. More... | |
void | WriteUInt64 (ulong value, int bits=64) |
Writes a 64-bit unsigned integer value to the buffer. More... | |
void | WriteUInt64AtOffset (ulong value, int offset, int bits) |
Writes a 64-bit unsigned integer value at a specified offset in the buffer. More... | |
void | WriteUInt64VarLength (ulong value, int blockSize) |
Writes a 64-bit unsigned integer value with variable length to the buffer. More... | |
Static Public Member Functions | |
static NetBitBuffer * | Allocate (int group, int size) |
Allocates a new NetBitBuffer with the specified group and size. More... | |
static Offset | GetOffset (NetBitBuffer *buffer) |
Gets the current offset of the specified buffer. More... | |
static void | Release (NetBitBuffer *buffer) |
Releases the specified buffer. More... | |
static void | ReleaseRef (ref NetBitBuffer *buffer) |
Releases the reference to the specified buffer and sets it to null. More... | |
Public Attributes | |
ulong * | _data |
ulong * | _dataBlockOriginal |
int | _group |
int | _lengthBits |
int | _lengthBytes |
int | _offsetBits |
NetAddress | Address |
The address of the buffer. More... | |
Static Public Attributes | |
const int | BITCOUNT = 64 |
const int | BYTESHIFT = 3 |
const int | INDEXSHIFT = 6 |
const ulong | MAXVALUE = ulong.MaxValue |
const int | USEDMASK = BITCOUNT - 1 |
Properties | |
int | BytesRemaining [get] |
Gets the number of bytes remaining in the buffer. More... | |
ulong * | Data [get] |
Gets or sets a pointer to the data in the buffer. More... | |
bool | Done [get, set] |
Gets a value indicating whether the buffer has been fully read. More... | |
bool | DoneOrOverflow [get, set] |
Gets a value indicating whether the buffer is done or has overflowed. More... | |
bool | IsOnEvenByte [get, set] |
Gets a value indicating whether the buffer is aligned to an even byte boundary. More... | |
int | LengthBits [get] |
Gets the length of the buffer in bits. More... | |
int | LengthBytes [get] |
Gets or sets the length of the buffer in bytes. More... | |
bool | MoreToRead [get, set] |
Gets a value indicating whether there is more data to read in the buffer. More... | |
int | OffsetBits [get, set] |
Gets or sets the current offset in bits. More... | |
int | OffsetBitsUnsafe [get, set] |
Gets or sets the current offset in bits without any safety checks. More... | |
int | OffsetBytes [get] |
Gets the current offset in bytes. More... | |
bool | Overflow [get, set] |
Gets a value indicating whether the buffer has overflowed. More... | |
Properties inherited from INetBitWriteStream | |
int | OffsetBits [get] |
Gets the current offset in bits. More... | |
Represents a buffer for reading and writing bits.
|
static |
Allocates a new NetBitBuffer with the specified group and size.
group | The group identifier for the buffer. |
size | The size of the buffer in bytes. |
bool CanRead | ( | int | bits | ) |
Checks if the specified number of bits can be read from the buffer.
bits | The number of bits to check. |
true
if the specified number of bits can be read; otherwise, false
.bool CanWrite | ( | int | bits | ) |
Checks if the specified number of bits can be written to the buffer.
bits | The number of bits to check. |
true
if the specified number of bits can be written; otherwise, false
.bool CheckBitCount | ( | int | count | ) |
Checks if the specified number of bits can be read or written without exceeding the buffer length.
count | The number of bits to check. |
true
if the specified number of bits can be read or written; otherwise, false
.void Clear | ( | ) |
Clears the buffer by setting all bits to zero.
byte* GetDataPointer | ( | ) |
Gets a pointer to the current data position in the buffer.
|
static |
Gets the current offset of the specified buffer.
buffer | The buffer to get the offset from. |
void PadToByteBoundary | ( | ) |
Pads the buffer to the next byte boundary by writing zero bits if necessary.
byte* PadToByteBoundaryAndGetPtr | ( | ) |
Pads the buffer to the next byte boundary and returns a pointer to the current data position.
bool PeekBoolean | ( | ) |
Peeks at the next boolean value in the buffer without advancing the read position.
bool ReadBoolean | ( | ) |
Reads a boolean value from the buffer.
byte ReadByte | ( | int | bits = 8 | ) |
Reads a byte value from the buffer.
bits | The number of bits to read. Default is 8. |
void ReadBytesAligned | ( | byte[] | buffer, |
int | length | ||
) |
Reads an array of bytes from the buffer, ensuring byte alignment.
buffer | The array to store the read bytes. |
length | The number of bytes to read. |
void ReadBytesAligned | ( | void * | buffer, |
int | length | ||
) |
Reads a block of bytes from the buffer, ensuring byte alignment.
buffer | A pointer to the block of bytes to store the read data. |
length | The number of bytes to read. |
double ReadDouble | ( | ) |
Reads a double-precision floating-point value from the buffer.
short ReadInt16 | ( | int | bits = 16 | ) |
Reads a 16-bit signed integer value from the buffer.
bits | The number of bits to read. Default is 16. |
int ReadInt32 | ( | int | bits = 32 | ) |
Reads a 32-bit signed integer value from the buffer.
bits | The number of bits to read. Default is 32. |
int ReadInt32VarLength | ( | ) |
Reads a 32-bit signed integer value with variable length from the buffer.
int ReadInt32VarLength | ( | int | blockSize | ) |
Reads a 32-bit signed integer value with variable length from the buffer.
blockSize | The block size in bits. |
long ReadInt64 | ( | int | bits = 64 | ) |
Reads a 64-bit signed integer value from the buffer.
bits | The number of bits to read. Default is 64. |
long ReadInt64VarLength | ( | int | blockSize | ) |
Reads a 64-bit signed integer value with variable length from the buffer.
blockSize | The block size in bits. |
float ReadSingle | ( | ) |
Reads a single-precision floating-point value from the buffer.
string ReadString | ( | ) |
Reads a string from the buffer using UTF-8 encoding.
string ReadString | ( | Encoding | encoding | ) |
Reads a string from the buffer using the specified encoding.
encoding | The encoding to use. |
ushort ReadUInt16 | ( | int | bits = 16 | ) |
Reads a 16-bit unsigned integer value from the buffer.
bits | The number of bits to read. Default is 16. |
uint ReadUInt32 | ( | int | bits = 32 | ) |
Reads a 32-bit unsigned integer value from the buffer.
bits | The number of bits to read. Default is 32. |
uint ReadUInt32VarLength | ( | ) |
Reads a 32-bit unsigned integer value with variable length from the buffer.
uint ReadUInt32VarLength | ( | int | blockSize | ) |
Reads a 32-bit unsigned integer value with variable length from the buffer.
blockSize | The block size in bits. |
ulong ReadUInt64 | ( | int | bits = 64 | ) |
Reads a 64-bit unsigned integer value from the buffer.
bits | The number of bits to read. Default is 64. |
ulong ReadUInt64VarLength | ( | int | blockSize | ) |
Reads a 64-bit unsigned integer value with variable length from the buffer.
blockSize | The block size in bits. |
|
static |
Releases the specified buffer.
buffer | The buffer to release. |
|
static |
Releases the reference to the specified buffer and sets it to null.
buffer | A reference to the buffer to release. |
void ReplaceDataFromBlockWithTemp | ( | int | tempSize | ) |
Replaces the current data block with a temporary block of the specified size.
tempSize | The size of the temporary block in bytes. |
void SeekToByteBoundary | ( | ) |
Advances the buffer offset to the next byte boundary.
void SetBufferLengthBytes | ( | ulong * | buffer, |
int | lenghtInBytes | ||
) |
Sets the buffer length in bytes and updates the internal length in bits.
buffer | A pointer to the buffer. |
lenghtInBytes | The length of the buffer in bytes. |
void Write | ( | ulong | value, |
int | bits | ||
) |
Writes a value to the buffer with a specified number of bits.
value | The value to write. |
bits | The number of bits to write. |
bool WriteBoolean | ( | bool | value | ) |
Writes a boolean value to the buffer.
value | The boolean value to write. |
Implements INetBitWriteStream.
void WriteByte | ( | byte | value, |
int | bits = 8 |
||
) |
Writes a byte value to the buffer.
value | The byte value to write. |
bits | The number of bits to write. Default is 8. |
void WriteBytesAligned | ( | byte[] | buffer, |
int | length | ||
) |
Writes an array of bytes to the buffer, ensuring byte alignment.
buffer | The array of bytes to write. |
length | The number of bytes to write. |
void WriteBytesAligned | ( | void * | buffer, |
int | length | ||
) |
Writes a block of bytes to the buffer, ensuring byte alignment.
buffer | A pointer to the block of bytes to write. |
length | The number of bytes to write. |
Implements INetBitWriteStream.
void WriteDouble | ( | double | value | ) |
Writes a double-precision floating-point value to the buffer.
value | The double-precision floating-point value to write. |
void WriteInt16 | ( | short | value, |
int | bits = 16 |
||
) |
Writes a 16-bit signed integer value to the buffer.
value | The 16-bit signed integer value to write. |
bits | The number of bits to write. Default is 16. |
void WriteInt32 | ( | int | value, |
int | bits = 32 |
||
) |
Writes a 32-bit signed integer value to the buffer.
value | The 32-bit signed integer value to write. |
bits | The number of bits to write. Default is 32. |
Implements INetBitWriteStream.
void WriteInt32AtOffset | ( | int | value, |
int | offset, | ||
int | bits | ||
) |
Writes a 32-bit integer value at a specified offset in the buffer.
value | The 32-bit integer value to write. |
offset | The offset in bits where the value should be written. |
bits | The number of bits to write. |
void WriteInt32VarLength | ( | int | value | ) |
Writes a 32-bit signed integer value with variable length to the buffer.
value | The 32-bit signed integer value to write. |
Implements INetBitWriteStream.
void WriteInt32VarLength | ( | int | value, |
int | blockSize | ||
) |
Writes a 32-bit signed integer value with variable length to the buffer.
value | The 32-bit signed integer value to write. |
blockSize | The block size in bits. |
Implements INetBitWriteStream.
void WriteInt64 | ( | long | value, |
int | bits = 64 |
||
) |
Writes a 64-bit signed integer value to the buffer.
value | The 64-bit signed integer value to write. |
bits | The number of bits to write. Default is 64. |
void WriteInt64VarLength | ( | long | value, |
int | blockSize | ||
) |
Writes a 64-bit signed integer value with variable length to the buffer.
value | The 64-bit signed integer value to write. |
blockSize | The block size in bits. |
void WriteSingle | ( | float | value | ) |
Writes a single-precision floating-point value to the buffer.
value | The single-precision floating-point value to write. |
void WriteSlow | ( | ulong | value, |
int | bits | ||
) |
Writes a value to the buffer with a specified number of bits, handling cases where the value spans multiple words.
value | The value to write. |
bits | The number of bits to write. |
void WriteString | ( | string | value | ) |
Writes a string to the buffer using UTF-8 encoding.
value | The string to write. |
void WriteString | ( | string | value, |
Encoding | encoding | ||
) |
Writes a string to the buffer using the specified encoding.
value | The string to write. |
encoding | The encoding to use. |
void WriteUInt16 | ( | ushort | value, |
int | bits = 16 |
||
) |
Writes a 16-bit unsigned integer value to the buffer.
value | The 16-bit unsigned integer value to write. |
bits | The number of bits to write. Default is 16. |
void WriteUInt32 | ( | uint | value, |
int | bits = 32 |
||
) |
Writes a 32-bit unsigned integer value to the buffer.
value | The 32-bit unsigned integer value to write. |
bits | The number of bits to write. Default is 32. |
void WriteUInt32VarLength | ( | uint | value | ) |
Writes a 32-bit unsigned integer value with variable length to the buffer.
value | The 32-bit unsigned integer value to write. |
void WriteUInt32VarLength | ( | uint | value, |
int | blockSize | ||
) |
Writes a 32-bit unsigned integer value with variable length to the buffer.
value | The 32-bit unsigned integer value to write. |
blockSize | The block size in bits. |
void WriteUInt64 | ( | ulong | value, |
int | bits = 64 |
||
) |
Writes a 64-bit unsigned integer value to the buffer.
value | The 64-bit unsigned integer value to write. |
bits | The number of bits to write. Default is 64. |
void WriteUInt64AtOffset | ( | ulong | value, |
int | offset, | ||
int | bits | ||
) |
Writes a 64-bit unsigned integer value at a specified offset in the buffer.
value | The 64-bit unsigned integer value to write. |
offset | The offset in bits where the value should be written. |
bits | The number of bits to write. |
void WriteUInt64VarLength | ( | ulong | value, |
int | blockSize | ||
) |
Writes a 64-bit unsigned integer value with variable length to the buffer.
value | The 64-bit unsigned integer value to write. |
blockSize | The block size in bits. |
Implements INetBitWriteStream.
NetAddress Address |
The address of the buffer.
|
get |
Gets the number of bytes remaining in the buffer.
|
get |
Gets or sets a pointer to the data in the buffer.
|
getset |
Gets a value indicating whether the buffer has been fully read.
|
getset |
Gets a value indicating whether the buffer is done or has overflowed.
|
getset |
Gets a value indicating whether the buffer is aligned to an even byte boundary.
|
get |
Gets the length of the buffer in bits.
|
get |
Gets or sets the length of the buffer in bytes.
|
getset |
Gets a value indicating whether there is more data to read in the buffer.
|
getset |
Gets or sets the current offset in bits.
|
getset |
Gets or sets the current offset in bits without any safety checks.
|
get |
Gets the current offset in bytes.
|
getset |
Gets a value indicating whether the buffer has overflowed.