How to Send Multi data types?

5 posts / 0 new
Last post
Offline
Last seen: 8 years 3 months ago
Joined: 11/24/2014
Posts: 26
How to Send Multi data types?

Hello,


I've started my research project by Rti DDS Connext,

I have 2 kind of data types :

struct bite_msg_t {
    string<128> color; //@key
    long x;
    long y;
   
};

struct bite_iam_reply_t {
    string<128> color; //@key
    short a;
    short b;
   
};

As i realized , for publishing these 2 kinds of data types , I should make 2 topics and 2 datawriters. and for subscribing , i should make 2 kinds of Listeners and 2 datareaders?

I've really confused to write the code for this simple project.

Would you please help me?

Gerardo Pardo's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 06/02/2010
Posts: 601

Hi,

If you know the collection of data-types that you may send then you can define a "union" type in IDL. A DataWriter of the "union" type can write any one type in the union. And similarly a DataReader of the "union" can read any of the types. The discriminator in the union defines which of the data-types you are actually writing, and in the reader side the DataReader first looks at the discriminator to determine the members of the union it should access.

The IDL union type for the two types that you describe above would be this:

struct bite_msg_t {
    string<128> color; //@key
    long x;
    long y;
};

struct bite_iam_reply_t {
    string<128> color; //@key
    short a;
    short b;
};

enum BiteMsgKinds {
   BITE_MSG,
   BITE_IAM_REPLY
};

union MultiTypes switch(BiteMsgKinds) {
    case BITE_MSG:
        bite_msg_t bite_msg;
    case BITE_IAM_REPLY:
        bite_iam_reply_t bite_iam_reply;
}; //@top-level

Gerardo

Offline
Last seen: 5 years 5 months ago
Joined: 09/25/2018
Posts: 5

Hi,

                     We have done the  same thing but how to set the descriminator value in publisher.

Regards,

kenil.

Gerardo Pardo's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 06/02/2010
Posts: 601

The specific API depends on the programming language.

What programming language are you using?

 

Offline
Last seen: 5 years 5 months ago
Joined: 09/25/2018
Posts: 5

Hello,

             c++ Traditional.

            I have another question. Is their anything to differentiate in subscriber if their is more than 1 publisher publishes the data?

Regards,

sudarshan.