Elegant serialization to/from variable-length C types?

I’m connecting Unreal to external programs using FSockets, but I’m having a little trouble parsing messages. I need to control exactly what bytes get read/written.

The way I do it now is to throw up my hands and forget about Unreal. I get my data from FUdpSocketReceiver as an ArrayReaderPtr, get a void pointer from its GetData() function, and then do it the bit banging C-style. It’s hideous.

Does anybody know a way to do this cleanly with FArchive and the << operator?

These message types have arbitrary length arrays that include their length in the message, so it’s hard to make code that works in both directions. Sending, you write the TArray’s Num() result to the length; receiving, you use the length to preallocate and copy array elements one by one to the TArray.