Added more error code to Packet class
This commit is contained in:
@@ -20,6 +20,10 @@ public:
|
||||
template<typename T>
|
||||
void AddPrimitive(T val)
|
||||
{
|
||||
// Check if we are trying to add more than the package can fit.
|
||||
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
||||
LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for!");
|
||||
}
|
||||
memcpy(m_Data + m_Offset, &val, sizeof(T));
|
||||
m_Offset += sizeof(T);
|
||||
}
|
||||
@@ -28,7 +32,7 @@ public:
|
||||
T PopFrontPrimitive()
|
||||
{
|
||||
if (m_Offset < m_ReturnDataOffset + sizeof(T)) {
|
||||
LOG_WARNING("Package PopFrontPrimitive(): You are trying to remove more than what exists in this package!");
|
||||
LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this package!");
|
||||
return -1;
|
||||
}
|
||||
T returnValue;
|
||||
@@ -51,6 +55,7 @@ private:
|
||||
char* m_Data;
|
||||
unsigned int m_ReturnDataOffset = 0;
|
||||
int m_Offset = 0;
|
||||
unsigned int m_MaxPacketSize = 128;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user