ValveKeyValue icon indicating copy to clipboard operation
ValveKeyValue copied to clipboard

Implement WideString

Open xPaw opened this issue 4 years ago • 1 comments

CS:GO implements it like this:

// write
{
	int nLength = dat->m_wsValue ? V_wcslen( dat->m_wsValue ) : 0;
	buffer.PutShort( nLength );
	for( int k = 0; k < nLength; ++ k )
	{
		buffer.PutShort( ( unsigned short ) dat->m_wsValue[k] );
	}
	break;
}

// read
{
	int nLength = buffer.GetShort();

	dat->m_wsValue = new wchar_t[nLength + 1];

	for( int k = 0; k < nLength; ++ k )
	{
		dat->m_wsValue[k] = buffer.GetShort();
	}
	dat->m_wsValue[ nLength ] = 0;
	break;
}

xPaw avatar Jan 19 '21 09:01 xPaw

So its just two bytes for length and then two bytes per char?

Seems simple enough, particularly given that char in .NET is already two bytes wide 😈

yaakov-h avatar Jan 19 '21 11:01 yaakov-h