Photon Fusion 2.0.3

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
NetBitBuffer Struct Reference

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 NetBitBufferAllocate (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...
 

Detailed Description

Represents a buffer for reading and writing bits.

Member Function Documentation

◆ Allocate()

static NetBitBuffer* Allocate ( int  group,
int  size 
)
static

Allocates a new NetBitBuffer with the specified group and size.

Parameters
groupThe group identifier for the buffer.
sizeThe size of the buffer in bytes.
Returns
A pointer to the allocated NetBitBuffer.

◆ CanRead()

bool CanRead ( int  bits)

Checks if the specified number of bits can be read from the buffer.

Parameters
bitsThe number of bits to check.
Returns
true if the specified number of bits can be read; otherwise, false.

◆ CanWrite()

bool CanWrite ( int  bits)

Checks if the specified number of bits can be written to the buffer.

Parameters
bitsThe number of bits to check.
Returns
true if the specified number of bits can be written; otherwise, false.

◆ CheckBitCount()

bool CheckBitCount ( int  count)

Checks if the specified number of bits can be read or written without exceeding the buffer length.

Parameters
countThe number of bits to check.
Returns
true if the specified number of bits can be read or written; otherwise, false.

◆ Clear()

void Clear ( )

Clears the buffer by setting all bits to zero.

◆ GetDataPointer()

byte* GetDataPointer ( )

Gets a pointer to the current data position in the buffer.

Returns
A pointer to the current data position in the buffer.

◆ GetOffset()

static Offset GetOffset ( NetBitBuffer buffer)
static

Gets the current offset of the specified buffer.

Parameters
bufferThe buffer to get the offset from.
Returns
An Offset struct representing the current offset.

◆ PadToByteBoundary()

void PadToByteBoundary ( )

Pads the buffer to the next byte boundary by writing zero bits if necessary.

◆ PadToByteBoundaryAndGetPtr()

byte* PadToByteBoundaryAndGetPtr ( )

Pads the buffer to the next byte boundary and returns a pointer to the current data position.

Returns
A pointer to the current data position in the buffer after padding to the byte boundary.

◆ PeekBoolean()

bool PeekBoolean ( )

Peeks at the next boolean value in the buffer without advancing the read position.

Returns
The boolean value peeked from the buffer.

◆ ReadBoolean()

bool ReadBoolean ( )

Reads a boolean value from the buffer.

Returns
The boolean value read from the buffer.

◆ ReadByte()

byte ReadByte ( int  bits = 8)

Reads a byte value from the buffer.

Parameters
bitsThe number of bits to read. Default is 8.
Returns
The byte value read from the buffer.

◆ ReadBytesAligned() [1/2]

void ReadBytesAligned ( byte[]  buffer,
int  length 
)

Reads an array of bytes from the buffer, ensuring byte alignment.

Parameters
bufferThe array to store the read bytes.
lengthThe number of bytes to read.

◆ ReadBytesAligned() [2/2]

void ReadBytesAligned ( void *  buffer,
int  length 
)

Reads a block of bytes from the buffer, ensuring byte alignment.

Parameters
bufferA pointer to the block of bytes to store the read data.
lengthThe number of bytes to read.

◆ ReadDouble()

double ReadDouble ( )

Reads a double-precision floating-point value from the buffer.

Returns
The double-precision floating-point value read from the buffer.

◆ ReadInt16()

short ReadInt16 ( int  bits = 16)

Reads a 16-bit signed integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 16.
Returns
The 16-bit signed integer value read from the buffer.

◆ ReadInt32()

int ReadInt32 ( int  bits = 32)

Reads a 32-bit signed integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 32.
Returns
The 32-bit signed integer value read from the buffer.

◆ ReadInt32VarLength() [1/2]

int ReadInt32VarLength ( )

Reads a 32-bit signed integer value with variable length from the buffer.

Returns
The 32-bit signed integer value read from the buffer.

◆ ReadInt32VarLength() [2/2]

int ReadInt32VarLength ( int  blockSize)

Reads a 32-bit signed integer value with variable length from the buffer.

Parameters
blockSizeThe block size in bits.
Returns
The 32-bit signed integer value read from the buffer.

◆ ReadInt64()

long ReadInt64 ( int  bits = 64)

Reads a 64-bit signed integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 64.
Returns
The 64-bit signed integer value read from the buffer.

◆ ReadInt64VarLength()

long ReadInt64VarLength ( int  blockSize)

Reads a 64-bit signed integer value with variable length from the buffer.

Parameters
blockSizeThe block size in bits.
Returns
The 64-bit signed integer value read from the buffer.

◆ ReadSingle()

float ReadSingle ( )

Reads a single-precision floating-point value from the buffer.

Returns
The single-precision floating-point value read from the buffer.

◆ ReadString() [1/2]

string ReadString ( )

Reads a string from the buffer using UTF-8 encoding.

Returns
The string read from the buffer.

◆ ReadString() [2/2]

string ReadString ( Encoding  encoding)

Reads a string from the buffer using the specified encoding.

Parameters
encodingThe encoding to use.
Returns
The string read from the buffer.

◆ ReadUInt16()

ushort ReadUInt16 ( int  bits = 16)

Reads a 16-bit unsigned integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 16.
Returns
The 16-bit unsigned integer value read from the buffer.

◆ ReadUInt32()

uint ReadUInt32 ( int  bits = 32)

Reads a 32-bit unsigned integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 32.
Returns
The 32-bit unsigned integer value read from the buffer.

◆ ReadUInt32VarLength() [1/2]

uint ReadUInt32VarLength ( )

Reads a 32-bit unsigned integer value with variable length from the buffer.

Returns
The 32-bit unsigned integer value read from the buffer.

◆ ReadUInt32VarLength() [2/2]

uint ReadUInt32VarLength ( int  blockSize)

Reads a 32-bit unsigned integer value with variable length from the buffer.

Parameters
blockSizeThe block size in bits.
Returns
The 32-bit unsigned integer value read from the buffer.

◆ ReadUInt64()

ulong ReadUInt64 ( int  bits = 64)

Reads a 64-bit unsigned integer value from the buffer.

Parameters
bitsThe number of bits to read. Default is 64.
Returns
The 64-bit unsigned integer value read from the buffer.

◆ ReadUInt64VarLength()

ulong ReadUInt64VarLength ( int  blockSize)

Reads a 64-bit unsigned integer value with variable length from the buffer.

Parameters
blockSizeThe block size in bits.
Returns
The 64-bit unsigned integer value read from the buffer.

◆ Release()

static void Release ( NetBitBuffer buffer)
static

Releases the specified buffer.

Parameters
bufferThe buffer to release.

◆ ReleaseRef()

static void ReleaseRef ( ref NetBitBuffer buffer)
static

Releases the reference to the specified buffer and sets it to null.

Parameters
bufferA reference to the buffer to release.

◆ ReplaceDataFromBlockWithTemp()

void ReplaceDataFromBlockWithTemp ( int  tempSize)

Replaces the current data block with a temporary block of the specified size.

Parameters
tempSizeThe size of the temporary block in bytes.

◆ SeekToByteBoundary()

void SeekToByteBoundary ( )

Advances the buffer offset to the next byte boundary.

◆ SetBufferLengthBytes()

void SetBufferLengthBytes ( ulong *  buffer,
int  lenghtInBytes 
)

Sets the buffer length in bytes and updates the internal length in bits.

Parameters
bufferA pointer to the buffer.
lenghtInBytesThe length of the buffer in bytes.

◆ Write()

void Write ( ulong  value,
int  bits 
)

Writes a value to the buffer with a specified number of bits.

Parameters
valueThe value to write.
bitsThe number of bits to write.

◆ WriteBoolean()

bool WriteBoolean ( bool  value)

Writes a boolean value to the buffer.

Parameters
valueThe boolean value to write.
Returns
The boolean value that was written.

Implements INetBitWriteStream.

◆ WriteByte()

void WriteByte ( byte  value,
int  bits = 8 
)

Writes a byte value to the buffer.

Parameters
valueThe byte value to write.
bitsThe number of bits to write. Default is 8.

◆ WriteBytesAligned() [1/2]

void WriteBytesAligned ( byte[]  buffer,
int  length 
)

Writes an array of bytes to the buffer, ensuring byte alignment.

Parameters
bufferThe array of bytes to write.
lengthThe number of bytes to write.

◆ WriteBytesAligned() [2/2]

void WriteBytesAligned ( void *  buffer,
int  length 
)

Writes a block of bytes to the buffer, ensuring byte alignment.

Parameters
bufferA pointer to the block of bytes to write.
lengthThe number of bytes to write.

Implements INetBitWriteStream.

◆ WriteDouble()

void WriteDouble ( double  value)

Writes a double-precision floating-point value to the buffer.

Parameters
valueThe double-precision floating-point value to write.

◆ WriteInt16()

void WriteInt16 ( short  value,
int  bits = 16 
)

Writes a 16-bit signed integer value to the buffer.

Parameters
valueThe 16-bit signed integer value to write.
bitsThe number of bits to write. Default is 16.

◆ WriteInt32()

void WriteInt32 ( int  value,
int  bits = 32 
)

Writes a 32-bit signed integer value to the buffer.

Parameters
valueThe 32-bit signed integer value to write.
bitsThe number of bits to write. Default is 32.

Implements INetBitWriteStream.

◆ WriteInt32AtOffset()

void WriteInt32AtOffset ( int  value,
int  offset,
int  bits 
)

Writes a 32-bit integer value at a specified offset in the buffer.

Parameters
valueThe 32-bit integer value to write.
offsetThe offset in bits where the value should be written.
bitsThe number of bits to write.

◆ WriteInt32VarLength() [1/2]

void WriteInt32VarLength ( int  value)

Writes a 32-bit signed integer value with variable length to the buffer.

Parameters
valueThe 32-bit signed integer value to write.

Implements INetBitWriteStream.

◆ WriteInt32VarLength() [2/2]

void WriteInt32VarLength ( int  value,
int  blockSize 
)

Writes a 32-bit signed integer value with variable length to the buffer.

Parameters
valueThe 32-bit signed integer value to write.
blockSizeThe block size in bits.

Implements INetBitWriteStream.

◆ WriteInt64()

void WriteInt64 ( long  value,
int  bits = 64 
)

Writes a 64-bit signed integer value to the buffer.

Parameters
valueThe 64-bit signed integer value to write.
bitsThe number of bits to write. Default is 64.

◆ WriteInt64VarLength()

void WriteInt64VarLength ( long  value,
int  blockSize 
)

Writes a 64-bit signed integer value with variable length to the buffer.

Parameters
valueThe 64-bit signed integer value to write.
blockSizeThe block size in bits.

◆ WriteSingle()

void WriteSingle ( float  value)

Writes a single-precision floating-point value to the buffer.

Parameters
valueThe single-precision floating-point value to write.

◆ WriteSlow()

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.

Parameters
valueThe value to write.
bitsThe number of bits to write.

◆ WriteString() [1/2]

void WriteString ( string  value)

Writes a string to the buffer using UTF-8 encoding.

Parameters
valueThe string to write.

◆ WriteString() [2/2]

void WriteString ( string  value,
Encoding  encoding 
)

Writes a string to the buffer using the specified encoding.

Parameters
valueThe string to write.
encodingThe encoding to use.

◆ WriteUInt16()

void WriteUInt16 ( ushort  value,
int  bits = 16 
)

Writes a 16-bit unsigned integer value to the buffer.

Parameters
valueThe 16-bit unsigned integer value to write.
bitsThe number of bits to write. Default is 16.

◆ WriteUInt32()

void WriteUInt32 ( uint  value,
int  bits = 32 
)

Writes a 32-bit unsigned integer value to the buffer.

Parameters
valueThe 32-bit unsigned integer value to write.
bitsThe number of bits to write. Default is 32.

◆ WriteUInt32VarLength() [1/2]

void WriteUInt32VarLength ( uint  value)

Writes a 32-bit unsigned integer value with variable length to the buffer.

Parameters
valueThe 32-bit unsigned integer value to write.

◆ WriteUInt32VarLength() [2/2]

void WriteUInt32VarLength ( uint  value,
int  blockSize 
)

Writes a 32-bit unsigned integer value with variable length to the buffer.

Parameters
valueThe 32-bit unsigned integer value to write.
blockSizeThe block size in bits.

◆ WriteUInt64()

void WriteUInt64 ( ulong  value,
int  bits = 64 
)

Writes a 64-bit unsigned integer value to the buffer.

Parameters
valueThe 64-bit unsigned integer value to write.
bitsThe number of bits to write. Default is 64.

◆ WriteUInt64AtOffset()

void WriteUInt64AtOffset ( ulong  value,
int  offset,
int  bits 
)

Writes a 64-bit unsigned integer value at a specified offset in the buffer.

Parameters
valueThe 64-bit unsigned integer value to write.
offsetThe offset in bits where the value should be written.
bitsThe number of bits to write.

◆ WriteUInt64VarLength()

void WriteUInt64VarLength ( ulong  value,
int  blockSize 
)

Writes a 64-bit unsigned integer value with variable length to the buffer.

Parameters
valueThe 64-bit unsigned integer value to write.
blockSizeThe block size in bits.

Implements INetBitWriteStream.

Member Data Documentation

◆ Address

NetAddress Address

The address of the buffer.

Property Documentation

◆ BytesRemaining

int BytesRemaining
get

Gets the number of bytes remaining in the buffer.

◆ Data

ulong* Data
get

Gets or sets a pointer to the data in the buffer.

◆ Done

bool Done
getset

Gets a value indicating whether the buffer has been fully read.

◆ DoneOrOverflow

bool DoneOrOverflow
getset

Gets a value indicating whether the buffer is done or has overflowed.

◆ IsOnEvenByte

bool IsOnEvenByte
getset

Gets a value indicating whether the buffer is aligned to an even byte boundary.

◆ LengthBits

int LengthBits
get

Gets the length of the buffer in bits.

◆ LengthBytes

int LengthBytes
get

Gets or sets the length of the buffer in bytes.

◆ MoreToRead

bool MoreToRead
getset

Gets a value indicating whether there is more data to read in the buffer.

◆ OffsetBits

int OffsetBits
getset

Gets or sets the current offset in bits.

◆ OffsetBitsUnsafe

int OffsetBitsUnsafe
getset

Gets or sets the current offset in bits without any safety checks.

◆ OffsetBytes

int OffsetBytes
get

Gets the current offset in bytes.

◆ Overflow

bool Overflow
getset

Gets a value indicating whether the buffer has overflowed.