0

Unreal Engine (C++)

Hi, I have a TArray of Bytes from TCP connection. I have 58 Bytes of header and 12 x 4 Bytes of Float32. I need to extract the 12 float32 numbers from my Array Bytes, I have tried this code for extracting the first number but the result is wrong every time:

float ReceivedUE4float32;
ReceivedUE4float32 = float(ReceivedData[58]); //58 index of first float32
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Dato intdex 58 ~> %f"), ReceivedUE4float32));

Can someone help me?

Socket: https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/index.md

Transform (12x4 Bytes): https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/transform.md

Melebius
  • 4,692
  • 3
  • 32
  • 43
Enrico
  • 11
  • 2

1 Answers1

1

float(ReceivedData[58]) will dereference the 58th byte from ReceivedData and create a float from that value, which is not what you want.

You can use reinterpret_cast to read the data:

float value = *(reinterpret_cast<float*>(ReceivedData + 58));

You did not mention which platforms you are targeting, but keep in mind this pays no attention to endianness.

Rotem
  • 19,723
  • 6
  • 57
  • 101