Putting Data Structure to a String then through CORBA Any

Posted on 2005-04-07
Last Modified: 2008-02-01
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
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*), sizeof WolfTwo);

now WolfTwo would have Wolf's data items of 1 1 as opposed to 10 10.
Question by:clim81
    LVL 86

    Expert Comment

    >>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();

    Author Comment

    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.

    Author Comment

    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.

    Author Comment

    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.
    LVL 1

    Accepted Solution

    PAQed with points (500) refunded

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now