/** @file jsonencoder.cpp
 *  Encoder implementation for JSON
 * 	@headerfile jsonencoder.h "EABaseTypesJson/jsonencoder.h"
 *	@author Chris Burns (cburns@ea.com)
 *
 *	UX
 *	(c) 2012 Electronic Arts Inc. 
 */

#include "EABaseTypesJson/jsonencoder.h"

#include "eajson/jsonwriter.h"

namespace EA
{
	namespace Types
	{
		JsonEncoder::JsonEncoder(EA::Json::JsonWriter *writer):
			mWriter(writer)
		{
		}

		JsonEncoder::~JsonEncoder()
		{
		}

		void JsonEncoder::Reset()
		{
			mWriter->Reset();
		}

		void JsonEncoder::BeginArray()
		{
			mWriter->BeginArray();
		}

		void JsonEncoder::EndArray()
		{
			mWriter->EndArray();
		}

		void JsonEncoder::BeginObject()
		{
			mWriter->BeginObject();
		}

		void JsonEncoder::EndObject()
		{
			mWriter->EndObject();
		}

		void JsonEncoder::BeginObjectValue(const char* key, size_t length)
		{
			mWriter->BeginObjectValue(key, length);
		}

		void JsonEncoder::Boolean(bool boolean)
		{
			mWriter->Bool(boolean);
		}

		void JsonEncoder::Number(EA::BaseTypeFloat number)
		{
			int64_t truncated = static_cast<int64_t>(number);

			if(static_cast<EA::BaseTypeFloat>(truncated) == number)
			{
				mWriter->Integer(truncated);
			}
			else
			{
				mWriter->Double(number);
			}
		}

		void JsonEncoder::String(const char* str, size_t length)
		{
			mWriter->String(str, length);
		}

		void JsonEncoder::Function(FunctionIn function)
		{
			const char* str = "<Function>";

			mWriter->String(str, strlen(str));
		}

		void JsonEncoder::UserData(UserDataIn userData)
		{
			const char* str = "<UserData>";

			mWriter->String(str, strlen(str));
		}

		void JsonEncoder::Null()
		{
			mWriter->Null();
		}
	}
}
