[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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.
0
clim81
Asked:
clim81
  • 3
1 Solution
 
jkrCommented:
>>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();
0
 
clim81Author Commented:
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.
0
 
clim81Author Commented:
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.
0
 
clim81Author Commented:
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.
0
 
DarthModCommented:
PAQed with points (500) refunded

DarthMod
Community Support Moderator
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now