[omniORB] Reading Any from stream?

amos at amos.mailshell.com amos at amos.mailshell.com
Tue Jul 26 15:33:45 BST 2005


Hello,

I'm still working on the object serialization/deserialization
and things seem to work but I don't like the fact that the
code looks strange.

I'm trying to move away from using a union of all "message
types" and towards using a CORBA::Any object.

Taking again the IDL of the sample type I try to serialize:

struct AddRealmOp {
  long id;
  string name;
};

I ended up with a code like the following to serialize it
in the CORBA Helper and then deserialize for testing proposes:

operationslog::AddRealmOp addRealmOp;
addRealmOp.id = id;
addRealmOp.name = name;
CORBA::Any *writeAny = new CORBA::Any();
*writeAny <<= addRealmOp;
	
cdrMemoryStream stream;

*writeAny >>= stream;
writeToDisk(stream.bufPtr(), stream.bufSize());

// Done writing serialized object to disk as "Any"
// Now start reading it and print the results

readFromDisk(buffer, bufferSize);
cdrMemoryStream stream(buffer, bufferSize);
CORBA::Any* anyp = new CORBA::Any();
*anyp <<= stream;
operationslog::AddRealmOp* checkOp;
if (*anyp >>= checkOp) {
  cout << "print checkOp's fields here";
} else {
  cout << "ERROR" << endl;
}
delete anyp;

My questions:
1. First and foremost - do you see any resource leaks in the code
above? From the text at the page mentioned below I understand that
I shouldn't delete checkOp, but what about anyp itself? Should I
delete it? Can I avoid calling new to initialize it?

2. I wonder why can't I use an automatic variable for "writeAny" and
"any". When I try to do this I get a compilation error like:
no match for 'operator<<' in 'writeAny << addRealmOp'

3. The above question is even more intriguing because in section
15.3.8, page 681 of "Advanced CORBA Programming with C++" there
is a sample code like the following:

CORBA::Any a;

BtData btd;
a <<= btd; // Copying insertion

And:

CORBA::Any a;
a >>= btd_p;

And my attempts to do the same don't pass compilation.

What am I doing wrong?  Or is it also to do with my use
of the OmniORB-specific cdrMemoryStream?

Thanks,

--Amos





More information about the omniORB-list mailing list