Пример #1
0
VError VJSONBinaryWriter::StreamArray(const VJSONArray *inArray, VMemoryBuffer<>& outBuff)
{
	VError err = VE_OK;
	
	if (inArray == NULL) // should it happen
	{
		sLONG nullarray = -2;
		outBuff.AddData(&nullarray, 4);
		return VE_OK;
	}
	
	else
	{
		sLONG count = (sLONG)inArray->GetCount();
		sLONG xcount = count; // so count can be optimized as a register
		outBuff.AddData(&xcount, 4);

		for( sLONG i = 0 ; (i < count) && (err == VE_OK) ; ++i)
		{
			err = StreamValue( (*inArray)[i], outBuff);
		}

	}
		
	return err;
}
Пример #2
0
VError VJSONBinaryWriter::StreamValue(const VJSONValue& inValue, VMemoryBuffer<>& outBuff)
{
	VError err = VE_OK;
	sBYTE btype = (sBYTE)inValue.GetType();
	outBuff.AddData(&btype, 1);
	switch( inValue.GetType())
	{
		case JSON_null:
		case JSON_undefined:
		case JSON_true:
		case JSON_false:
			{
				break;
			}
			
		case JSON_string:
			{
				const VInlineString* s = &(inValue.fString);
				sLONG len = (sLONG)s->GetLength();
				outBuff.AddData(&len, 4);
				if (len > 0)
					outBuff.AddData(s->GetCPointer(), len * 2);
				break;
			}

		case JSON_date:
			{
				outBuff.AddData(&inValue.fTimeStamp, sizeof(sLONG8));
				break;
			}

		case JSON_number:
			{
				outBuff.AddData(&inValue.fNumber, sizeof(Real));
				break;
			}

		case JSON_array:
			{
				err = StreamArray( inValue.GetArray(), outBuff);
				break;
			}

		case JSON_object:
			{
				err = StreamObject( inValue.GetObject(), outBuff);
				break;
			}
		
		default:
			xbox_assert( false);
	}
	
	return err;
}
Пример #3
0
VError VJSONBinaryWriter::StreamObject(const VJSONObject *inObject, VMemoryBuffer<>& outBuff)
{
	if (inObject == NULL) // should it happen
	{
		sWORD nullobj = -2;
		outBuff.AddData(&nullobj, 2);
		return VE_OK;
	}

	if (std::find( fStack.begin(), fStack.end(), inObject) != fStack.end())
	{
		return vThrowError( VE_JSON_STRINGIFY_CIRCULAR);
	}

	VError err = VE_OK;

	fStack.push_back( inObject);
	
	//if (!inObject->doStream( outBuff, *this, &err))
	{
		for (VJSONPropertyConstOrderedIterator i(inObject); i.IsValid() && (err == VE_OK); ++i)
		{
			const VString& name = i.GetName();
			sWORD len = (sWORD)name.GetLength();
			outBuff.AddData(&len, 2);
			if (len > 0)
			{
				outBuff.AddData(name.GetCPointer(), (sLONG)len * 2);
				err = StreamValue(i.GetValue(), outBuff);
			}
		}

		sWORD endobj = -1;
		outBuff.AddData(&endobj, 2);
	}

	fStack.pop_back();
	
	return err;
}
// Environment block == null-terminated block of null-terminated strings of the form: name=value\0
wchar_t * XWinProcessLauncher::_CreateEnvironmentVariablesBlock(const EnvVarNamesAndValuesMap &inVarToUse)
{
	wchar_t *		initialEnvStrings	= NULL;
	VMemoryBuffer<>	allStrings;
	wchar_t *		theEnvVarBlock		= NULL;

	// Initial environment variables

	initialEnvStrings = ::GetEnvironmentStringsW();
	if(initialEnvStrings != NULL)
	{
		wchar_t	*currentStr = initialEnvStrings;
		size_t	fullStrSize;

		while (*currentStr)
		{
			fullStrSize = ::wcslen(currentStr) + 1;
			allStrings.PutData(allStrings.GetDataSize(), currentStr, fullStrSize * sizeof(wchar_t));
			currentStr += fullStrSize;
		}
	}

	// Prepare our envir. variables
	if(!inVarToUse.empty())
	{
		XBOX::VString							oneEnvVarAndValue;
		EnvVarNamesAndValuesMap::const_iterator	envVarIterator;

		// Calculate final buffer size (concatenate name=value and add the 0 terminattion)
		 
		for (envVarIterator = inVarToUse.begin(); envVarIterator != inVarToUse.end(); envVarIterator++)
		{
			oneEnvVarAndValue = envVarIterator->first;
			if(!oneEnvVarAndValue.IsEmpty())
			{
				oneEnvVarAndValue += "=";
				oneEnvVarAndValue += envVarIterator->second;

				const wchar_t *	varValueCStr = oneEnvVarAndValue.GetCPointer();	// Null terminated UniCode string.

				if(testAssert(varValueCStr != NULL))
				{
					allStrings.PutData(allStrings.GetDataSize(), varValueCStr, (oneEnvVarAndValue.GetLength() + 1) * sizeof(wchar_t));				
				}
			}						
		}
	} //if(!inVarToUse.empty())

	if(allStrings.GetDataSize() > 0)
	{
		wchar_t	theZero = 0;

		allStrings.PutData(allStrings.GetDataSize(), &theZero, sizeof(wchar_t));

		theEnvVarBlock = new wchar_t[allStrings.GetDataSize()];
		if(testAssert(theEnvVarBlock))
			allStrings.GetData(0, theEnvVarBlock, allStrings.GetDataSize());
	}
	
	if(initialEnvStrings != NULL)
		::FreeEnvironmentStringsW(initialEnvStrings);

	return theEnvVarBlock;
}
// Environment block == null-terminated block of null-terminated strings of the form: name=value\0
char * XWinProcessLauncher::_CreateEnvironmentVariablesBlock(const EnvVarNamesAndValuesMap &inVarToUse)
{
	char	*initialEnvStrings = NULL;
	VMemoryBuffer<>		allStrings;
	char * theEnvVarBlock = NULL;

	// Initial environment variables
	initialEnvStrings = ::GetEnvironmentStrings();
	if(initialEnvStrings != NULL)
	{
		char *currentStr = initialEnvStrings;
		size_t	fullStrSize;
		while(*currentStr)
		{
			fullStrSize = strlen(currentStr) + 1;
			allStrings.PutData(allStrings.GetDataSize(), currentStr, fullStrSize);
			currentStr += fullStrSize;
		}
	}

	// Prepare our envir. variables
	if(!inVarToUse.empty())
	{
		XBOX::VString	oneEnvVarAndValue;
	// Calculate final buffer size (concatenate name=value and add the 0 terminattion)
		EnvVarNamesAndValuesMap::const_iterator	envVarIterator = inVarToUse.begin();
		while(envVarIterator != inVarToUse.end())
		{
			oneEnvVarAndValue = envVarIterator->first;
			if(!oneEnvVarAndValue.IsEmpty())
			{
				oneEnvVarAndValue += "=";
				oneEnvVarAndValue += envVarIterator->second;

				char *varValueCStr = _CreateCString(oneEnvVarAndValue);
				if(testAssert(varValueCStr != NULL))
				{
					allStrings.PutData(allStrings.GetDataSize(), varValueCStr, strlen(varValueCStr) + 1);
					delete [] varValueCStr;
				}
			}			
			++envVarIterator;
		}
	} //if(!inVarToUse.empty())

	if(allStrings.GetDataSize() > 0)
	{
		char	theZero = 0;
		allStrings.PutData(allStrings.GetDataSize(), &theZero, 1);

		theEnvVarBlock = new char[allStrings.GetDataSize()];
		if(testAssert(theEnvVarBlock))
			allStrings.GetData(0, theEnvVarBlock, allStrings.GetDataSize());
	}
	
	if(initialEnvStrings != NULL)
		::FreeEnvironmentStrings(initialEnvStrings);
	
	return theEnvVarBlock;

}