In the general case, to enable a user-defined type for transmission, it must derive from the abstract base class TPO::Message.
class TPO::Message {
virtual void serialize(TPO::Message_data&) const = 0;}
virtual void deserialize(TPO::Message_data&) = 0;}
};
TPO::Message defines the pure virtual methods serialize and
deserialize which must be implemented by the user-defined class. The are
responsible for sending and receving the user-defined type, repsectively. For both
methods, the TPO++ library provides an argument of type TPO::Message_data which
is used to marshall the objects data. TPO::Message_data provides
insert() and extract() methods, which can be supplied all legal
datatypes including containers and other user-defined types. serialize() calls
repeatedly insert() to prepare the objects member for transmission, and,
symmetrically, deserialize() uses extract() the receive the objects
member data. An example may illustrate this:
// Dynamic user-defined object
class my_complex : public TPO::Message {
public:
my_complex() : im(0.0), re(0.0) {}
void serialize(Message_data& m) const {
m.insert(im);
m.insert(re);
}
void deserialize(Message_data& m) {
m.extract(im);
m.extract(re);
}
private:
double re;
double im;
};
TPO_MARSHALL_DYNAMIC(my_complex);