Download

Casting or parsing byte arrays into an array of structures?

I’m trying to figure out how to take a byte array and turn it into an array of structures in blueprint. I’m using the TCP plugin https://www.unrealengine.com/marketplace/en-US/slug/tcp-socket-plugin which returns a byte array “message” in blueprint. I’m trying to figure out how to do this in blueprint so some non-coders can make their own message handling blueprints.

The stream coming in over TCP is a bunch of 24 byte structures that look something like this:

uint8_t cmd_length
uint8_t cmd_id
int16_t accelX
int16_t accelY
int16_t accelZ
int16_t gyroX
int16_t gyroY
int16_t gyroZ
int16_t temperature
uint32_t time_stamp
uint32_t sample_number

So each “message” array I get back from the plugin might contain as many as 30 of these. In C you could just cast the byte array to this structure and then read the members of the structure. Or worst case you could memcopy the byte array over to an equivalent sized array of this structure. Is there some way to do this in blueprints?

I assume I would create a structure in blueprints, but I don’t see the equivalent of a cast or “bytes into struct” and “struct into bytes” operation. Is there one that I’m missing?

For extra bonus fun, since it’s TCP the “message” might end in the middle of one of these structures, with the rest of the structure being in the next message, any ideas on how to handle this case?