[omniORB] Need to save Any to void* - serialise it?

David Riddoch djr@uk.research.att.com
Tue, 20 Apr 1999 17:03:59 +0100 (GMT)



I suppose you might want to be able to read it back again ... so here's an
improved version ...


void omniORB_write_any(const CORBA::Any& a, int fd)
{
  MemBufferedStream s;
  a >>= s;
  s.rewind_in_mkr();

  CORBA::ULong len = a.alreadyWritten();
  write(fd, &len, 4);  // NB. Byte order specific
  write(fd, a.data(), len);
}


void omniORB_read_any(CORBA::Any& a, int fd)
{
  CORBA::ULong len;
  read(fd, &len, 4);  // NB. Byte order specific

  char* buf = new char[len];
  read(fd, buf, len);

  MemBufferedStream s(buf, len);
  a <<= s;

  delete[] buf;
}


Insertion and extraction from the stream s could potentially raise a
CORBA::MARSHAL exception if there is an error. You will probably also want
to check that the length is sensible, and check the return values of read
and write.