Is FString::ToBlob Broken?

I’m trying to create a buffer to send data across the network. I had it working using char* into uint8* however working with FString is likely going to be easier in the long run, especially if I want to add BluePrint support.

FString serialized = "Test|Test|Test|Test|Test";
uint32 bufferSize = serialized.Len() * 0.5;
uint8* buffer = new uint8[bufferSize];

bool success = FString::ToBlob(serialized, buffer, bufferSize);

The buffer contains only this

\0

If I create a buffer using the below method it works as intended

char* serialized = "Test|Test|Test|Test|Test";
uint8* buffer = reinterpret_cast<uint8*>(serialized);

Am I missing something with FString? Should I be preparing my buffer differently?

Posting my own answer, didn’t end up solving it for ToBlob but managed to get FString into a uint8.

I should mention this is for a server running nodejs and expecting UTF8 encoding. It’s possible to send UTF16 to nodejs but it’s twice the size.

FString serialized = message.GetSerialized();
TCHAR *serializedChar = serialized.GetCharArray().GetData();
int32 size = FCString::Strlen(serializedChar);
int32 sent = 0;

socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent);

#Alternative Using FBufferArchive

FString YourMessage = "Weee!";

FBufferArchive BinaryArrayArchive;
BinaryArrayArchive << YourMessage;

now you can access the uint8* ptr using

BinaryArrayArchive.GetTypedData() //this is uint8*

and use the rest of your code from the point of having the uint8*

:slight_smile:

FBufferArchive

It is both a TArray and a FArchiveWriter

Enjoy!

Rama

1 Like

rama, how do you get it back into fstring?