$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] [serialization] RPC, IDL, XDR
From: remi.chateauneu_at_[hidden]
Date: 2008-10-20 17:40:52
Is there an attempt to use boost::serialization and Sun's XDR routines 
to make remote procedure calls with C++ objects? IDL allows only to 
serialize plain C variables but it might be possible to wrap elegantly 
low-level XDR calls. Something like that:
/// This wraps an XDR pointer into a pseudo-archive.
struct xdr_archive
{
    XDR * _xdr_ptr ;
    xdr_archive( XDR * xp ) : _xrd_ptr(xp) {};
    bool_t operator & ( int & i ) { return xdr_int( _xdr_ptr, & i ); };
    bool_t operator & ( float & f ) { return xdr_float( _xdr_ptr, & f ); };
  ...
}
The advantage of this is that, if a class has a 
boost::serialization-compliant 'serialize' method, it becomes easily 
usable with RPC. For example:
/// Sample structure/
struct MyStruct
{
  int _i ;
  float _f ;
  template<class Archive >
  void /serialize( ///Archive & ar, const unsigned int version) {
    ar & _i;
    ar & _f;
  }
  friend void xdr( XDR * xp, MyStruct * sp )
  {
    s->serialize( xdr_archive( xp ), 0 );
  };
};
Although not losing the boolean return value of xdr functions is not 
straightforward (exceptions or a data member in xdr_archive ?), I would 
like to know whether it makes sense to use 'serialization' this way. The 
advantage would be: No need to use an IDL compiler such as rpcgen, less 
code maintenance, usability of XDR for C++ objects (not just C).