Suppose I have two classes:
class1 {
int m_i;
std::string m_s;
};
class2 {
int m_i2;
class1 *m_ptr;
};
Now, I want to send a class2 variable over network, and want to use any of the libraries that does serialization.(Protocol-buffers, Thrift, MessagePack..)
Which one can I use?(note the class1* m_ptr)
Using google protocol buffers, you would need a .proto file (say test.proto) like:
Using C++, once you run the protoc compiler against this, you end up with test.pb.cc and test.pb.h
You can then use these like:
Note, for the sake of brevity I’m not doing any error checking or exception handling here – this would be needed in production code. I’m also not managing the lifetime of the
class1pointer.