public bool TryAddPacket(IPacketBase packet)
{
fixed (byte* buf = DataBuffer)
{
int packetSize = packet.Header.SizeInBytes;
if (m_usedBytes + packetSize < BUFFER_SIZE)
{
//Copy packet into buffer
Marshal.StructureToPtr(packet, (IntPtr)(buf + m_usedBytes), false);
//Update used bytes and packet count
m_usedBytes += (short)packetSize;
m_packetCount++;
//Update actual size
m_header.SizeInBytes = (short)(Marshal.SizeOf(this) - BUFFER_SIZE + m_usedBytes);
return true;
}
}
return false;
}