Added more error code to Packet class

This commit is contained in:
Jocke
2015-12-17 17:32:49 +01:00
parent 000adb198f
commit db5b6ad519
2 changed files with 23 additions and 6 deletions
+6 -1
View File
@@ -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