DataReader/DataWriter for primitive types

3 posts / 0 new
Last post
Offline
Last seen: 8 years 5 months ago
Joined: 10/12/2015
Posts: 5
DataReader/DataWriter for primitive types

Hi, 

Currently I was able to write string to topic and read from topic. I also understand I can defined user types and dynamic data types. 

Is there way to write and read primite types only ( like, double, boolean) ? 

Thanks, 

Biswanath

Organization:
Offline
Last seen: 1 week 13 hours ago
Joined: 04/02/2013
Posts: 195

Hi Biswanath,

The Modern C++ API has a utility that may be what you're looking for (it requires C++11 support in your compiler):

In this HOWTO look for "Manipulating data reflectively using C++ tuples."

This will let you directly use C++11 tuples of primitive types, without any IDL type definition.

Gerardo Pardo's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 06/02/2010
Posts: 601

Hi,

For the other API's you need to define a "wrapper" structure and run rtiddsgen on it. For example to send a primitive double you would define:

struct DoubleType {
    double value;
};  

Note that on the wire you only send the double itself so there is no overheard caused by having it wrapped inside the DoubleType structure.

I am interested to know more about the use case that is making you want to send just the primitive types... One reason we did not add these primitives as types built-in is that we have not found it to be a common or recommended practice. In many situations applications end up not sending just primitive values. Rather it becomes more approriate to send a sequence of them, and/or include a key (e.g. the sensorId that generated that value), some identification of the quality or error, units etc.  These additional fields make the use of the data less error prone and the overhead introduced by the use of a network prototocol normally dwarfs the cost of these additional fields.

Gerardo