DataReader/DataWriter for primitive types

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


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) ? 



Last seen: 1 month 3 days ago
Joined: 04/02/2013
Posts: 151

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
Last seen: 2 months 2 weeks ago
Joined: 06/02/2010
Posts: 594


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.