// DWBS ------------------------------------------------------------------ DWBS
//
// PLATFORM		: ALL
// PRODUCT		: BIT_DEMON
// VISIBILITY	: PUBLIC
//
// DWBS ------------------------------------------------------------------ DWBS

#include <bdLobby/bdMessageStore/bdMessageTypes/bdFriendSessionInvitationMessage.h>

bdFriendSessionInvitationMessage::bdFriendSessionInvitationMessage(const bdUInt messageType)
: bdUserNotificationMessage(messageType),
  m_attachmentSize(0),
  m_attachment(BD_NULL)
{
	bdMemset(m_secID.ab, 0, BD_SECURITY_ID_LENGTH);
}

bdFriendSessionInvitationMessage::~bdFriendSessionInvitationMessage()
{
	if(m_attachment)
	{
		bdMemory::deallocate(m_attachment);
	}
}

bdBool bdFriendSessionInvitationMessage::deserialize(bdBitBufferRef buffer)
{
	bdBool ok = bdUserNotificationMessage::deserialize(buffer);
	bdUInt length = BD_SECURITY_ID_LENGTH;
	
	ok = ok && buffer->readBlob(&m_secID.ab[0], length);
	ok = ok && buffer->readUInt16(m_attachmentSize);
	
	if (ok && (m_attachmentSize > 0))
	{
		if(m_attachment)
		{
			bdMemory::deallocate(m_attachment);
		}
		m_attachment = bdMemory::allocate(m_attachmentSize);
		
		bdUInt32 size = m_attachmentSize;
		ok = ok && buffer->readBlob(reinterpret_cast<bdUByte8*>(m_attachment), size);
	}

	return ok;
}
