multiple type in single topic

2 posts / 0 new
Last post
Offline
Last seen: 5 years 5 months ago
Joined: 09/25/2018
Posts: 5
multiple type in single topic

I have two publishers which can publish the data with same domain id's but different topics. Now can i have a single subscriber with same domain id(publishers) having single topic with multiple types and access the data sending by the publishers.

Example:

publisher 1:                                 publisher 2:                                        subscriber 1:

struct temp {                                struct press{                                      struct both {

float temperature;                         double pressure;                                 float temperature;

};                                                 };                                                       double pressure;

                                                                                                             };

Offline
Last seen: 1 week 5 days ago
Joined: 04/02/2013
Posts: 195

You can. This is a possible way to model that:

@mutable @autoid
struct temp {
 float temperature;
};

@mutable @autoid
struct press {
  double pressure;
};

@mutable @autoid
struct both {
  @optional float temperature;
  @optional double pressure; 
};

The annotation @mutable allows the most flexible type evolution, which includes removing or adding members in any position. The @autoid annotation generates identifiers for each member automatically based on their name. The @optional annotation changes the binding of that member into the programming language so you can know if the member was received or not (for example, in C it makes temperature and pressure pointers, so if they're NULL you know they were not received).

Note that both publishers and the subscriber will need to use the same topic name.