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

#include <bdLobby/bdStorage/bdLobbyFileHeader.h>

bdLobbyFileHeader::bdLobbyFileHeader()
:	m_fileID(0),
	m_createTime(0),
	m_modifedTime(0),
	m_ownerType(BD_MAX_OWNER_TYPE),
	m_visibility(BD_MAX_VISIBILITY_TYPE),
	m_ownerID(0),
	m_fileSize(0)
{
	bdMemset(m_fileName, 0, BD_MAX_FILE_NAME_LENGTH);
}

bdLobbyFileHeader::~bdLobbyFileHeader()
{
}

bdBool bdLobbyFileHeader::deserialize(bdBitBufferRef buffer)
{
	bdBool ok = true;
	//ok = ok && buffer->readUInt32(m_fileSize);
	ok = ok && buffer->readUInt64(m_fileID);
	ok = ok && buffer->readUInt32(m_createTime);
	ok = ok && buffer->readUInt32(m_modifedTime);

	bdBool ownerPublisher = false;
	ok = ok && buffer->readBool(ownerPublisher);

	if(ownerPublisher)
	{
		m_ownerType = bdLobbyFileHeader::BD_OWNER_PUBLISHER;
	}
	else
	{
		m_ownerType = bdLobbyFileHeader::BD_OWNER_USER;
	}

	bdBool visibilityPrivate = false;
	ok = ok && buffer->readBool(visibilityPrivate);
	if(visibilityPrivate)
	{
		m_visibility = bdLobbyFileHeader::BD_VISIBLE_PRIVATE;
	}
	else
	{
		m_visibility = bdLobbyFileHeader::BD_VISIBLE_PUBLIC;
	}

	ok = ok && buffer->readUInt64(m_ownerID);
	ok = ok && buffer->readString(m_fileName, BD_MAX_FILE_NAME_LENGTH);
	return ok;
}

bdUInt64 bdLobbyFileHeader::getFileID() const
{
	return m_fileID;
}

bdUInt32 bdLobbyFileHeader::getCreationTime() const
{
	return m_createTime;
}

bdUInt32 bdLobbyFileHeader::getModifiedTime() const
{
	return m_modifedTime;
}

bdLobbyFileHeader::bdOwnerType bdLobbyFileHeader::getOwnerType() const
{
	return m_ownerType;
}

bdLobbyFileHeader::bdVisibility bdLobbyFileHeader::getVisibility() const
{
	return m_visibility;
}

const bdNChar8* bdLobbyFileHeader::getFileName() const
{
	return m_fileName;
}

bdUInt32 bdLobbyFileHeader::getFileSize() const
{
	return m_fileSize;
}

void bdLobbyFileHeader::setFileSize(bdUInt32 fileSize)
{
	m_fileSize = fileSize;
}
