#include "BinaryString.h"
#include <string.h>
#include "TciData.h"
#include <malloc.h>
#ifdef _WIN32
	#ifdef _MSC_VER
		#if _MSC_VER >= 1600
			#include <stdint.h>
		#else
			typedef int int32_t;
		#endif
	#else
		#include <stdint.h>
	#endif
#else
#include <stdint.h>
#endif

int getBinaryStringStartingPosition(const BinaryString *bs)
{
	if(!bs || !bs->aux)
		return 0;
	else
	{
		int nStructVersion = 0;
		memcpy(&nStructVersion, bs->aux, sizeof(int32_t));
		if(nStructVersion == 1)
		{
			char *ptr = (char*)bs->aux + sizeof(int32_t);
			AdditionalDataV1 * data = (AdditionalDataV1 *)ptr;
			return data->nBitPosition;
		}
	}
	return 0;
}

void setBinaryStringStartingPosition(BinaryString *bs, int nBitPosition)
{
	int nStructVersion = 0;
	if(!bs)
		return;
	if(bs->aux == 0)
	{
		nStructVersion = 1;
		bs->aux = (void *)malloc(sizeof(int32_t) + sizeof(AdditionalDataV1));
		memcpy(bs->aux,&nStructVersion, sizeof(int32_t));
	}
	else
		memcpy(&nStructVersion, bs->aux, sizeof(int32_t));
	if(nStructVersion == 1)
	{
		char *ptr = (char*)bs->aux + sizeof(int32_t);
		AdditionalDataV1 * data = (AdditionalDataV1 *)ptr;
		data->nBitPosition = nBitPosition;
	}
}
