![]() |
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes are stored in a ringbuffer of constant size; if more than that size is requested, the write operation fails. More...
#include <ByteBuffer.h>
Public Member Functions | |
bool | CanReadBytes (size_t a_Count) const |
Returns true if the specified amount of bytes are available for reading. More... | |
bool | CanWriteBytes (size_t a_Count) const |
Returns true if the specified amount of bytes are available for writing. More... | |
cByteBuffer (size_t a_BufferSize) | |
void | CheckValid (void) const |
Checks if the internal state is valid (read and write positions in the correct bounds) using ASSERTs. More... | |
void | CommitRead (void) |
Removes the bytes that have been read from the ringbuffer. More... | |
size_t | GetDataStart (void) const |
Returns the current data start index. More... | |
size_t | GetFreeSpace (void) const |
Returns the number of bytes that can be successfully written to the ringbuffer. More... | |
size_t | GetReadableSpace (void) const |
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already) More... | |
size_t | GetUsedSpace (void) const |
Returns the number of bytes that are currently in the ringbuffer. More... | |
void | ReadAgain (ContiguousByteBuffer &a_Out) |
Re-reads the data that has been read since the last commit to the current readpos. More... | |
void | ReadAll (ContiguousByteBuffer &a_Data) |
Reads all available data into a_Data. More... | |
bool | ReadBEDouble (double &a_Value) |
bool | ReadBEFloat (float &a_Value) |
bool | ReadBEInt16 (Int16 &a_Value) |
bool | ReadBEInt32 (Int32 &a_Value) |
bool | ReadBEInt64 (Int64 &a_Value) |
bool | ReadBEInt8 (Int8 &a_Value) |
bool | ReadBEUInt16 (UInt16 &a_Value) |
bool | ReadBEUInt32 (UInt32 &a_Value) |
bool | ReadBEUInt64 (UInt64 &a_Value) |
bool | ReadBEUInt8 (UInt8 &a_Value) |
bool | ReadBool (bool &a_Value) |
bool | ReadBuf (void *a_Buffer, size_t a_Count) |
Reads a_Count bytes into a_Buffer; returns true if successful. More... | |
bool | ReadLEInt (int &a_Value) |
bool | ReadSome (ContiguousByteBuffer &a_String, size_t a_Count) |
Reads a_Count bytes into a_String; returns true if successful. More... | |
bool | ReadToByteBuffer (cByteBuffer &a_Dst, size_t a_NumBytes) |
Reads the specified number of bytes and writes it into the destinatio bytebuffer. More... | |
bool | ReadUUID (cUUID &a_Value) |
template<typename T > | |
bool | ReadVarInt (T &a_Value) |
Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned short, char, Byte, double, ...) More... | |
bool | ReadVarInt32 (UInt32 &a_Value) |
bool | ReadVarInt64 (UInt64 &a_Value) |
bool | ReadVarUTF8String (AString &a_Value) |
bool | ReadXYZPosition64 (int &a_BlockX, int &a_BlockY, int &a_BlockZ) |
bool | ReadXZYPosition64 (int &a_BlockX, int &a_BlockY, int &a_BlockZ) |
void | ResetRead (void) |
Restarts next reading operation at the start of the ringbuffer. More... | |
bool | SkipRead (size_t a_Count) |
Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer. More... | |
bool | Write (const void *a_Bytes, size_t a_Count) |
Writes the bytes specified to the ringbuffer. More... | |
bool | WriteBEDouble (double a_Value) |
bool | WriteBEFloat (float a_Value) |
bool | WriteBEInt16 (Int16 a_Value) |
bool | WriteBEInt32 (Int32 a_Value) |
bool | WriteBEInt64 (Int64 a_Value) |
bool | WriteBEInt8 (Int8 a_Value) |
bool | WriteBEInt8 (std::byte a_Value) |
bool | WriteBEUInt16 (UInt16 a_Value) |
bool | WriteBEUInt32 (UInt32 a_Value) |
bool | WriteBEUInt64 (UInt64 a_Value) |
bool | WriteBEUInt8 (UInt8 a_Value) |
bool | WriteBool (bool a_Value) |
bool | WriteBuf (const void *a_Buffer, size_t a_Count) |
Writes a_Count bytes into a_Buffer; returns true if successful. More... | |
bool | WriteLEInt32 (Int32 a_Value) |
bool | WriteVarInt32 (UInt32 a_Value) |
bool | WriteVarInt64 (UInt64 a_Value) |
bool | WriteVarUTF8String (const AString &a_Value) |
bool | WriteXYZPosition64 (Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ) |
bool | WriteXZYPosition64 (Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ) |
~cByteBuffer () | |
Static Public Member Functions | |
static size_t | GetVarIntSize (UInt32 a_Value) |
Gets the number of bytes that are needed to represent the given VarInt. More... | |
Protected Member Functions | |
void | AdvanceReadPos (size_t a_Count) |
Advances the m_ReadPos by a_Count bytes. More... | |
Protected Attributes | |
std::byte * | m_Buffer |
size_t | m_BufferSize |
size_t | m_DataStart |
size_t | m_ReadPos |
size_t | m_WritePos |
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes are stored in a ringbuffer of constant size; if more than that size is requested, the write operation fails.
The bytes stored can be retrieved using various ReadXXX functions; these assume that the needed number of bytes are present in the buffer (ASSERT; for performance reasons). The reading doesn't actually remove the bytes, it only moves the internal read ptr. To remove the bytes, call CommitRead(). To re-start reading from the beginning, call ResetRead(). This class doesn't implement thread safety, the clients of this class need to provide their own synchronization.
Definition at line 31 of file ByteBuffer.h.
cByteBuffer::cByteBuffer | ( | size_t | a_BufferSize | ) |
Definition at line 85 of file ByteBuffer.cpp.
cByteBuffer::~cByteBuffer | ( | ) |
Definition at line 100 of file ByteBuffer.cpp.
|
protected |
Advances the m_ReadPos by a_Count bytes.
Definition at line 989 of file ByteBuffer.cpp.
bool cByteBuffer::CanReadBytes | ( | size_t | a_Count | ) | const |
Returns true if the specified amount of bytes are available for reading.
Definition at line 213 of file ByteBuffer.cpp.
bool cByteBuffer::CanWriteBytes | ( | size_t | a_Count | ) | const |
Returns true if the specified amount of bytes are available for writing.
Definition at line 224 of file ByteBuffer.cpp.
void cByteBuffer::CheckValid | ( | void | ) | const |
Checks if the internal state is valid (read and write positions in the correct bounds) using ASSERTs.
Definition at line 1004 of file ByteBuffer.cpp.
void cByteBuffer::CommitRead | ( | void | ) |
Removes the bytes that have been read from the ringbuffer.
Definition at line 945 of file ByteBuffer.cpp.
|
inline |
Returns the current data start index.
For debugging purposes.
Definition at line 50 of file ByteBuffer.h.
size_t cByteBuffer::GetFreeSpace | ( | void | ) | const |
Returns the number of bytes that can be successfully written to the ringbuffer.
Definition at line 160 of file ByteBuffer.cpp.
size_t cByteBuffer::GetReadableSpace | ( | void | ) | const |
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already)
Definition at line 194 of file ByteBuffer.cpp.
size_t cByteBuffer::GetUsedSpace | ( | void | ) | const |
Returns the number of bytes that are currently in the ringbuffer.
Note GetReadableBytes()
Definition at line 181 of file ByteBuffer.cpp.
|
static |
Gets the number of bytes that are needed to represent the given VarInt.
Definition at line 1014 of file ByteBuffer.cpp.
void cByteBuffer::ReadAgain | ( | ContiguousByteBuffer & | a_Out | ) |
Re-reads the data that has been read since the last commit to the current readpos.
Used by ProtoProxy to duplicate communication
Definition at line 967 of file ByteBuffer.cpp.
void cByteBuffer::ReadAll | ( | ContiguousByteBuffer & | a_Data | ) |
Reads all available data into a_Data.
Definition at line 909 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEDouble | ( | double & | a_Value | ) |
Definition at line 363 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEFloat | ( | float & | a_Value | ) |
Definition at line 349 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEInt16 | ( | Int16 & | a_Value | ) |
Definition at line 261 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEInt32 | ( | Int32 & | a_Value | ) |
Definition at line 291 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEInt64 | ( | Int64 & | a_Value | ) |
Definition at line 321 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEInt8 | ( | Int8 & | a_Value | ) |
Definition at line 235 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEUInt16 | ( | UInt16 & | a_Value | ) |
Definition at line 277 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEUInt32 | ( | UInt32 & | a_Value | ) |
Definition at line 307 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEUInt64 | ( | UInt64 & | a_Value | ) |
Definition at line 335 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBEUInt8 | ( | UInt8 & | a_Value | ) |
Definition at line 248 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBool | ( | bool & | a_Value | ) |
Definition at line 377 of file ByteBuffer.cpp.
bool cByteBuffer::ReadBuf | ( | void * | a_Buffer, |
size_t | a_Count | ||
) |
Reads a_Count bytes into a_Buffer; returns true if successful.
Definition at line 796 of file ByteBuffer.cpp.
bool cByteBuffer::ReadLEInt | ( | int & | a_Value | ) |
Definition at line 464 of file ByteBuffer.cpp.
bool cByteBuffer::ReadSome | ( | ContiguousByteBuffer & | a_String, |
size_t | a_Count | ||
) |
Reads a_Count bytes into a_String; returns true if successful.
Definition at line 859 of file ByteBuffer.cpp.
bool cByteBuffer::ReadToByteBuffer | ( | cByteBuffer & | a_Dst, |
size_t | a_NumBytes | ||
) |
Reads the specified number of bytes and writes it into the destinatio bytebuffer.
Returns true on success.
Definition at line 920 of file ByteBuffer.cpp.
bool cByteBuffer::ReadUUID | ( | cUUID & | a_Value | ) |
Definition at line 533 of file ByteBuffer.cpp.
|
inline |
Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned short, char, Byte, double, ...)
Definition at line 79 of file ByteBuffer.h.
bool cByteBuffer::ReadVarInt32 | ( | UInt32 & | a_Value | ) |
Definition at line 392 of file ByteBuffer.cpp.
bool cByteBuffer::ReadVarInt64 | ( | UInt64 & | a_Value | ) |
Definition at line 414 of file ByteBuffer.cpp.
bool cByteBuffer::ReadVarUTF8String | ( | AString & | a_Value | ) |
Definition at line 436 of file ByteBuffer.cpp.
bool cByteBuffer::ReadXYZPosition64 | ( | int & | a_BlockX, |
int & | a_BlockY, | ||
int & | a_BlockZ | ||
) |
Definition at line 483 of file ByteBuffer.cpp.
bool cByteBuffer::ReadXZYPosition64 | ( | int & | a_BlockX, |
int & | a_BlockY, | ||
int & | a_BlockZ | ||
) |
Definition at line 508 of file ByteBuffer.cpp.
void cByteBuffer::ResetRead | ( | void | ) |
Restarts next reading operation at the start of the ringbuffer.
Definition at line 956 of file ByteBuffer.cpp.
bool cByteBuffer::SkipRead | ( | size_t | a_Count | ) |
Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer.
Definition at line 893 of file ByteBuffer.cpp.
bool cByteBuffer::Write | ( | const void * | a_Bytes, |
size_t | a_Count | ||
) |
Writes the bytes specified to the ringbuffer.
Returns true if successful, false if not
Definition at line 111 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEDouble | ( | double | a_Value | ) |
Definition at line 680 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEFloat | ( | float | a_Value | ) |
Definition at line 667 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEInt16 | ( | Int16 | a_Value | ) |
Definition at line 587 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEInt32 | ( | Int32 | a_Value | ) |
Definition at line 615 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEInt64 | ( | Int64 | a_Value | ) |
Definition at line 641 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEInt8 | ( | Int8 | a_Value | ) |
Definition at line 551 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEInt8 | ( | std::byte | a_Value | ) |
Definition at line 563 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEUInt16 | ( | UInt16 | a_Value | ) |
Definition at line 602 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEUInt32 | ( | UInt32 | a_Value | ) |
Definition at line 628 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEUInt64 | ( | UInt64 | a_Value | ) |
Definition at line 654 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBEUInt8 | ( | UInt8 | a_Value | ) |
Definition at line 575 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBool | ( | bool | a_Value | ) |
Definition at line 693 of file ByteBuffer.cpp.
bool cByteBuffer::WriteBuf | ( | const void * | a_Buffer, |
size_t | a_Count | ||
) |
Writes a_Count bytes into a_Buffer; returns true if successful.
Definition at line 829 of file ByteBuffer.cpp.
bool cByteBuffer::WriteLEInt32 | ( | Int32 | a_Value | ) |
bool cByteBuffer::WriteVarInt32 | ( | UInt32 | a_Value | ) |
Definition at line 705 of file ByteBuffer.cpp.
bool cByteBuffer::WriteVarInt64 | ( | UInt64 | a_Value | ) |
Definition at line 727 of file ByteBuffer.cpp.
bool cByteBuffer::WriteVarUTF8String | ( | const AString & | a_Value | ) |
Definition at line 749 of file ByteBuffer.cpp.
Definition at line 766 of file ByteBuffer.cpp.
Definition at line 781 of file ByteBuffer.cpp.
|
protected |
Definition at line 145 of file ByteBuffer.h.
|
protected |
Definition at line 146 of file ByteBuffer.h.
|
protected |
Definition at line 148 of file ByteBuffer.h.
|
protected |
Definition at line 150 of file ByteBuffer.h.
|
protected |
Definition at line 149 of file ByteBuffer.h.