Boost logo

Boost Users :

From: Larry Smith (larry.i.smith_at_[hidden])
Date: 2006-11-24 17:48:39


We have thousands of 'packed' 'C' structs (2100+) shared
between C and C++ modules & apps. These structures do NOT
contain any pointers, all data is contiguous so that it
may be transferred directly from one machine's memory to
another machine's memory without translation (32 bit Windows
on Intel), e.g.

#ifdef __cplusplus
extern "C" {
#endif

typedef struct NODE_MGR
{
  char ApplName[8];
  char CompName[8];
} NODE_MGR;

typedef struct ROUTE_CONTROL
{
  UCHAR msg_type;
  ULONG req_num;
  char src_domain_id[ 15 ];
  char src_machine_id[ 8 ];
  char src_proc_id[ 32 ];
  char dest_domain_id[ 15 ];
  char dest_machine_id[ 8 ];
  char dest_proc_id[ 32 ];
  NODE_MGR PrimeNodeMgr;
  NODE_MGR BkupNodeMgr;
  UINT parmlen;
  UINT datalen;
    /* data[] is actually 'parmlen + datalen' bytes
     * in length (64K max) and contains arrays of
     * other struct's who's types vary based on the values
     * of 'msg_type' and 'req_num'.
     */
  char data[ 1 ];
} ROUTE_CONTROL;

 /* hundreds of other struct defs here... */

#ifdef __cplusplus
}
#endif

Currently, these structs are written directly from the
workstation's memory to a TCP/IP socket connected to a
remote server process which reads them from the socket
directly into memory for immediate use by the server
program (i.e. 'packed' binary structs are transfered over
the net from one 32 bit Windows machine to another 32 bit
Windows machine).

In the near future the workstations will continue to
be 32 bit Windows, but the servers may be 32 bit Linux
on Intel, or 64 bit Linux on AMD, or 64 bit Linux on PowerPC,
or 64 bit Solaris on Sparc. This means that we can
no longer send/receive 32 bit Intel 'packed' binary structs
directly from the workstation to the server.

I had hoped to use Boost Archives to serialize the
structs to a std::string (via std::strstream), send
it across the net, then deserialize the structs at the
server. However, the structs have thousands of members of
the form 'char[N]' representing char arrays which are
NOT nul-terminated. I can not get these struct members to
serialize; I get compile errors, e.g. this fails to compile:

   ar & fld; // where fld is: char[200]

What's the secret trick?

The structs also contain many 'double' fields.
If the precision is the (default?) 6 when serialized,
that won't be enough. Is there a way to control
the precision of doubles when they are written to
a text archive?

Thanks,
Larry


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net