c++ - working with a stringstream, how do i unparse these strings? -
I have a TCP client that receives data from the server as a stringstream. The server packs vectors (floats) in a big string and separates them from the flag. Now in my client, I separate these flags again, and store them in string arrays. Therefore each "token" should be a vector. But I just can not parse it back Strings look very strange to me, take a look:
So again, I just need to do this in 3 layers it is parsed back. On behalf of the server it was sent as:
data.addFlag (11); Data & lt; & Lt; Pelvis.x () & lt; & Lt; Pelvis.y () & lt; & Lt; Pelvis.z (); Data.addFlag (12); Data & lt; & Lt; Rhip.x () & lt; & Lt; Rhip.y () & lt; & Lt; Rhip.z (); Where operator is overloaded
operator < & Lt; (Const float & amp; f) {m_buf.append (reinterpret_cast & lt; const char * & gt; (& amp; f), shape (f)); Return * This; } Edit: A token looks like this: if I call it
float First = * reint_past & lt; Float * & gt; (Value) I get an exception.
The wire looks fine, you just have to understand that when you change the four elements you will not get human readable objects. You can see here how Floats is represented as a binary:
So if you have float 1.01 then you will get binary 00111111100000010100011110101110 which is hex 0x3f8147ae If you see each byte in an eighty table So you will see that those bytes can be garbage.
In your problem: if you see, you will see that each float has 4 bytes.
So suppose you have a string of 12 bytes (which you want), you should know that there are 3 floats. To get them out, get 4 bytes at a time and interpret them again
(untested code)
string data = (although you've got data) Float first = * reinterpret_cast & lt; Name * & gt; (And data [0]); Float second = * reint_past & lt; Float * & gt; (& Amp; data [4]); Float third = * reinterpret_cast & lt; Float * & gt; (& Amp; data [8]); It is the same.
EDIT: It seems that I forgot to define the indicator.
For an example here, see:
Comments
Post a Comment