#ifndef EA_GAMETALK_UTILITY_H
#define EA_GAMETALK_UTILITY_H

#include "GameTalk/GameTalkBase.h"
// I believe we can't include GameTalkInstance because it would create a circular dependency?
//#include "GameTalk\GameTalkInstance.h"

namespace EA
{
	namespace GameTalk
	{
		class GameTalkInstance;

        // message handler function prototype
		typedef void (EA::GameTalk::GameTalkInstance::*GameTalkReceiverFnc)(void* buffer, unsigned int sizeInBytes);

		namespace Utility
		{
			class Parser
			{
			public:
				Parser(EA::GameTalk::GameTalkReceiverFnc callback, GameTalkInstance * gameTalkInstance);

				// Tells us whether the Parser is in the middle of parsing a GameTalkMessage
				bool WaitingForData();

				void DigestReceivedData(const char *receivedBytes, 
					uint32_t numReceivedBytes);

				USE_GAMETALK_ALLOC("GameTalk::Parser")
			private:
				Parser();
				Parser(const Parser & parser);
				Parser& operator=(const Parser & parser);

				void ReadFromBuffer();

				// The receivedBytes pointer that is passed into this function will be moved one byte forward
				bool GetMessageSize(char *receivedBytes, uint32_t numReceivedBytes, uint32_t *msgSizeRequirements) const;

				EA::GameTalk::GameTalkReceiverFnc mCallback;
				EA::GameTalk::GameTalkInstance * mGameTalkInstance;

				// Read index
				uint32_t mBufferMsgIndex;
				// Current size of buffer
				uint32_t mBufferMsgSize;
				// Message buffer
				char mBufferMessage[GAMETALK_MAX_BUFFER_SIZE];
				char mBufferMessageTemp[GAMETALK_MAX_BUFFER_SIZE];
			};
		}
	}
}

#endif


