C
C
cunion2021-01-14 21:01:42
C++ / C#
cunion, 2021-01-14 21:01:42

Is it possible to serialize class objects that do not have a serialize method?

Hello! I used the serialization of the boost library and when trying to serialize an object of the class "boost::asio::ip::tcp::endpoint" I got an error: "The class ... does not have a serialize method". I had a question, is it possible to serialize an object that does not contain this method through boost, if not, what good libraries for serialization / de-serialization exist.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2021-01-15
@vanyamba-electronics

Well, a simple example:

typedef struct {
    char* name;
} MyStruct;

Suppose you serialized it with the following method:
void serialize(ostream& os, const MyStruct& obj)
{
   char* p = (char*) obj;
   for (int n = 0; n != sizeof(MyStruct); ++n)
      os << *p;
}

And what's the point of storing the value of the obj.name pointer?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question