networking - Network protocol object serialization in C++ -
I am writing some C ++ code which will send data to TCP / IP I want to get this code portable on Linux / Windows / OSX Now, because this is the first time that I write portable network code, I need some general functions to add some items such as:
class myclass {... member ... Public: String Serialize () {std :: ostringstream out (); Outside & lt; & Lt; Member1; Outside & lt; & Lt; Member2; Outside & lt; & Lt; Member3; Return Out. (); }}
... which I now need it Anyway, I started reading the ostringstream related docs and exited the binary / text problem. Actually this line will change the brake in the correct order of every system. For example, suppose a member is an indicator that has four * fu = "hello \ man \ n", which is translated into a few byte sequences on Linux, the other on the windows ... and so on. My bytes will go to a packet on the Internet, a separate OS machine will teach them and I think that will be disturbed ... I have now read that I ostringstream
with ostringstream (ios:: Bin)
... this will solve the problem (provided that I will use a de-serialization function which will use istringstream (ios :: bin)
??? Confused about, if you can spend some clarity lines which would greatly appreciate
Thank you.
If all the great libraries are like you ?
From your goals:
Data portability - The stream of bytes built on a platform should be readable on any other.
You can also have 4 and 5 points of interest:
- Save and restore a deep pointer. That is, save and restore points Is saved Su is restored.
- share data proper restoration of indicators
Comments
Post a Comment