Link to home
Start Free TrialLog in
Avatar of clim81
clim81

asked on

Putting Data Structure to a String then through CORBA Any

I created a string that has the data structure of an object.  I'm trying to pass it through the CORBA Any, but it doesn't seem to take all the data structure through.

Client Side
ie.
class Animal
  int wolfsize;
  int wolfweight;
...

Animal Wolf(1,1)
string test((char*)&Wolf, sizeof Wold)

CORBA::Any a;
a <<= (CORBA::String_var)test;
const char* ptest;


Server Side
a >>= ptest;

string newstring = "";

newstring.append(ptest, sizeof Wolf);
Animal WolfTwo(10,10);
memcpy((char*)&WolfTwo, (char*)newstring.data(), sizeof WolfTwo);

now WolfTwo would have Wolf's data items of 1 1 as opposed to 10 10.
Avatar of jkr
jkr
Flag of Germany image

>>Animal Wolf(1,1)
>>string test((char*)&Wolf, sizeof Wold)

That cannot work - at all. You should consider providing a 'to_string()' method for the classes you want to send via CORBA, e.g. like

class Animal {
 int wolfsize;
 int wolfweight;

 string to_string() {

   stringstream ss;

   ss << wolfsize << " " << wolfweight;

   return ss.str();
 }
//...
};

Animal Wolf(1,1);
string test = Wolf.to_string();
Avatar of clim81
clim81

ASKER

Let me rephrase then.  I want the message of string test((char*)&Wolf, sizeof Wolf) to go through a CORBA::Any message.  And i just want to be able to get that string on the other side.
When I do it without going through a CORBA message it works fine.
Avatar of clim81

ASKER

The only reason i can't use a to_string() is because the actual item I want to use it on, I do not know the data structure layout.
Avatar of clim81

ASKER

please close the question.
I have found that Corba Any terminates a string if it hits a NULL character.  I had to encapsulate the data in a sequence and then put the sequence in the CORBA Any.
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial