[omniORB] Streaming Any's

David Riddoch djr@uk.research.att.com
Thu, 9 Nov 2000 09:52:48 +0000 (GMT)


Hi Kevin,


I gave a solution to this problem a while back at:
  http://www.uk.research.att.com/omniORB/archives/1999-04/0104.html

However, that has a typo-not-bug(!), so here is a corrected version:

---------------------------

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

  CORBA::ULong len = s.alreadyWritten();
  write(fd, &len, 4); // NB. Byte order specific
  write(fd, s.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;
}

---------------------------

NB. Yes, I know, I haven't put in any error
checking.


Cheers,
David


On Wed, 8 Nov 2000, Kevin Bailey wrote:

> I understand there's no way to convert an Any to a stream of
> bytes and back again portably (this side of CORBA 3.0). I was
> going to use it for a persistence store which didn't know
> anything about the things it was storing. It would need to store
> user-defined structs, arrays, sequences, and the like. Does
> omniORB have anything proprietary that can accomplish this ?
> 
> If not, is my best bet to write something myself using
> DynAny's ? Or, since it seems like a very useful thing, has
> someone already done this ?
> 
> Thanks,
> krb
> 
> 

------------------------
djr@uk.research.att.com at work, david@riddoch.org.uk otherwise