void WriteDynamicString ( std::ostream &output, const char *string )
{
	if ( string ) 
    {
		int size = strlen(string);
		WritePackedInt(output, size);
        output.write( string, size );
	}
	else 
    {
		int size = -1;
		WritePackedInt(output, size);
	}
}
示例#2
0
//--------------------------------------------------------------------------
void VeBinaryOStream::AppendStringAligned4(const VeChar8* pcData,
	VeSizeT stLength) noexcept
{
	WritePackedInt(stLength);
	AddBlob(pcData, stLength);
	VeSizeT stTemp = (stLength >= 255) ? 4 : 1;
	stTemp += stLength;
	stTemp = ((stTemp + 3) & (~3)) - stTemp;
	if (stTemp)
	{
		VeUInt32 u32Zero = 0;
		AddBlob(&u32Zero, stTemp);
	}
}
示例#3
0
//--------------------------------------------------------------------------
void VeBinaryOStream::AppendStringAligned4(const VeChar8* pcData, VeInt32 i32Length)
{
	VE_ASSERT(i32Length > 0);
	WritePackedInt(i32Length);
	AddBlob(pcData, i32Length);
	VeUInt32 u32Temp = (i32Length >= 255) ? 4 : 1;
	u32Temp += i32Length;
	u32Temp = ((u32Temp + 3) & 0xfffffffc) - u32Temp;
	if(u32Temp)
	{
		VeUInt32 u32Zero = 0;
		AddBlob(&u32Zero, u32Temp);
	}
}
示例#4
0
//--------------------------------------------------------------------------
void VeBinaryOStream::WriteStringLength(VeSizeT stValue) noexcept
{
	WritePackedInt(stValue);
}
示例#5
0
//--------------------------------------------------------------------------
void VeBinaryOStream::AppendString(const VeChar8* pcData,
	VeSizeT stLength) noexcept
{
	WritePackedInt(stLength);
	AddBlob(pcData, stLength);
}
// Writes a wchar_t out as length field + UTF-16 stream
void WriteUnicodeString ( std::ostream &output, const wchar_t *unicode )
{
	if ( unicode ) 
    {
#ifdef TARGET_OS_MACOSX
		// wchar_t = UTF-32, so we need to convert
		CFStringRef utf16 = CFStringCreateWithBytes(NULL, (UInt8 *)unicode, wcslen(unicode)*sizeof(wchar_t),
													kUTF32Encoding, false);
		int size = CFStringGetLength(utf16);
		WritePackedInt(output, size);
        for(int i = 0; i < size; ++ i)
        {
			WriteNetworkValue( output, CFStringGetCharacterAtIndex(utf16, i) );
        }
		
		CFRelease(utf16);
#elif defined( TARGET_OS_LINUX )
		// wchar_t is 4 byes on linux, so we need to convert
		int size = wcslen(unicode);

		size_t bufferSize = sizeof(unsigned short) * size * 2;
		size_t outBytesLeft = bufferSize;
		size_t inBytesLeft = size * sizeof(wchar_t);

		char *inBuf = (char *) unicode;
		char *buf = new char[ outBytesLeft ];
		char *outBuf = buf;

		iconv_t utf32_to_utf16 = iconv_open( "UTF16LE", "UTF32LE" );
		if( utf32_to_utf16 == (iconv_t) -1 )
		{
			perror("Failed to open iconv from UTF32LE -> UTF16LE" );
			delete[] buf;
			return;
		}
		size_t result = iconv( utf32_to_utf16, &inBuf, &inBytesLeft, &outBuf, &outBytesLeft );
		if( result == (size_t) -1 )
		{
			perror( "Failed to convert from UTF32LE -> UTF16LE" );
			delete[] buf;
			return;
		}
		iconv_close( utf32_to_utf16 );

		int bytesConverted = bufferSize - outBytesLeft;
		WritePackedInt(output, bytesConverted / sizeof(unsigned short) );
		output.write( buf, bytesConverted );
		delete[] buf;
#else
		// assume Windows and wchar_t = UTF-16
		int size = wcslen(unicode);
		WritePackedInt(output, size);
        for(int i = 0; i < size; ++ i)
        {
			WriteNetworkValue( output, unicode[i] );
        }
#endif
	}
	else 
    {
		int size = -1;
		WritePackedInt(output, size);
	}
}
示例#7
0
//--------------------------------------------------------------------------
void VeBinaryOStream::WriteStringLength(VeInt32 i32Length)
{
	WritePackedInt(i32Length);
}
示例#8
0
//--------------------------------------------------------------------------
void VeBinaryOStream::AppendString(const VeChar8* pcData, VeInt32 i32Length)
{
	VE_ASSERT(i32Length > 0);
	WritePackedInt(i32Length);
	AddBlob(pcData, i32Length);
}