Let's say I have a topic defined as a union like this on one system:
union MyType switch (letterId) {
case a: TypeA typeA;
case b: TypeB typeB;
case c: TypeC typeC;
};
But another system is not interested in the topic in the event that the union is sent in the form of TypeC. In fact, defining TypeC itself has a large amount of dependencies and it would be more convenient to just omit it. Can I then define the topic in system 2 as this since they will still have the same name?
union MyType switch (letterId) {
case a: TypeA typeA;
case b: TypeB typeB;
};
Would it just not work at all? If it would work what would happen when it does receive a TypeC?
Topics do not have to be defined in the exact same way for every DomainParticipant. The OMG DDS-XTypes specification describes how types of Topics can contain optional fields and how they can be extended or modified -- or not.
For DataWriters and DataReaders to match, their types need to be compatible according to the section 7.2.4 Type Compatibility in the specification. That same section defines rules about how the assigning happens between compatible types that have different definitions.
For union types, the first row in Table 7.17 - Definition of the is-assignable-from relationship for aggregated types will tell you what you can do with your union definition while keeping it compatible between different versions.
As a quick assessment: 7.2.2.4.4.5 Optional Members mentions that Union members, including the discriminator, shall never be optional, so you might have to find a creative solution for you particular situation.
Note that not all DDS vendors support the XTypes type system.