I\'m trying to serialize objects to send over network through a socket using only STL. I\'m not finding a way to keep objects\' structure to be deserialized in the other host. I
You can serialize with anything. All serialization means is that you are converting the object to bytes so that you can send it over a stream (like an std::ostream
) and read it with another (like an std::istream
). Just override operator <<(std::ostream&, const T&)
and operator >>(std::istream&, T&)
where T
is each of your types. And all the types contained in your types.
However, you should probably just use an already-existing library (Boost is pretty nice). There are tons of things that a library like Boost does for you, like byte-ordering, taking care of common objects (like arrays and all the stuff from the standard library), providing a consistent means of performing serialization and tons of other stuff.