convert a Data with a mutable DataType to a data With another mutable DataType

7 posts / 0 new
Last post
Offline
Last seen: 1 hour 55 min ago
Joined: 09/10/2022
Posts: 59
convert a Data with a mutable DataType to a data With another mutable DataType

Hello.


I know that I can convert samples of a DataType to a DynamicData with rti::core::xtypes::convert function.
Also I know that it's possible to convert that DynamicData to the DataType vice versa.

The question is that is it possible to convert DynamicData that created from a mutable DataType, to a DynamicData of another mutable DataType?
Is converting between datas of mutable DataTypes is possible just by sending data by DataWriter of TypeA and receiving data by DataReader of TypeB OR converting is also possible in code?

Howard's picture
Offline
Last seen: 23 hours 21 min ago
Joined: 11/29/2012
Posts: 664

I'm not sure how you think two different data types would be converted automatically. 

Just because 2 fields have the same basic type doesn't mean they represent the same thing, e.g. a "float temp" and a "float pressure" should not be mapped to each other.

Similarly, just because 2 fields have the same name doesn't mean they represent the same thing.  It's not possible for an automated algorithm to map one arbitrary datatype to another.

Coverting a data structure to a DynamicData representation of the same datatype is completely different.  The datatype isn't changed.  Only how the values are represented and stored in memory is changed.

So, while you can convert a mutable DataType into a DynamicData representation of the same data type, you can't convert a mutable type into a different multable type.

HOWEVER, the purpose of a "mutable" type is that the definition of the mutable type can change while preserving some level of interoperability between data of two different definitions of the SAME mutable type.

e.g.

Version 1

@mutable 
struct Position {
    @id(1) float x;
    @id(2) float y;
};

Version 2

@mutable 
struct Position {
    @id(1) float x;
    @id(2) float y;
    @id(3) float z;
};

With mutable datatypes, the ID's of a field cannot change between versions of the datatype.  You may add or remove, but you can't change the basic datatype or member name of an existing ID field.   

But with mutable datatypes, you can publish one version and subscribe to the other.  Extra fields sent will be cut.  Missing fields that were not sent will be set to default values.

Please refer to the following documentation:

https://community.rti.com/static/documentation/connext-dds/current/doc/manuals/connext_dds_professional/extensible_types_guide/extensible_types/Type_Safety_and_System_Evolution.htm?Highlight=%40mutable

https://community.rti.com/static/documentation/connext-dds/current/doc/manuals/connext_dds_professional/extensible_types_guide/extensible_types/XTypes_Title.htm

 

Offline
Last seen: 1 hour 55 min ago
Joined: 09/10/2022
Posts: 59

You told "you can't change the basic datatype or member name of an existing ID field" that is not true.

Of course I should be aware about what I'm doing in types and I should be aware about mapping fields But with TypeConsistency qos you can ignore_member_names in structs and ignore_enum_literal_names in enums. So for matching two mutable data types its enouph that members with same id have not different data type. I dont know any other forced rule.

My question was that is maping (converting) two data type just possible by publish/subscribe or its possible by code too?

Howard's picture
Offline
Last seen: 23 hours 21 min ago
Joined: 11/29/2012
Posts: 664

DDS does not allow you to publish one data type and subscribe to the same topic defined by a different data type.

You can have 2 versions of the same data type, and publish with one and subscribe by another as I described.

You could use the RTI Routing Service and a transformation for the Routing Service to convert the data from one data type to another.

Offline
Last seen: 1 hour 55 min ago
Joined: 09/10/2022
Posts: 59

Do you mean when I change name of a type (strust that used as topic type) or name of an struct (that used as type of a field) or I change an enum's name then publishing and subscribing is not valid and dds won't garanty validity of received values?

How does DDS detects that two types are different types, or they are two version of one type?

Howard's picture
Offline
Last seen: 23 hours 21 min ago
Joined: 11/29/2012
Posts: 664

When you have a DataWriter for a topic of datatype "A" and a DataReader of the same topic but of datatype "B", DDS won't allow the connection.  This will be a type mismatch.  And a Topic incompatibility status will be flagged.

struct A { ...  };

struct B { ... };

DDS "detects" that two types are the same type by the name of the type.  The definition of the types may be different (and depending on QoS settings making them incompatible), but because the same data type name is used, DDS will assume that they are referring to the same type.

Offline
Last seen: 1 hour 55 min ago
Joined: 09/10/2022
Posts: 59

Based on my tests, the mismatch does not occur with changing name of type, and rti admin console  does not show mismatch and it allows to subscribe one of the types. I like the ability of changing type name. Also this is what I understand from examples of Extensible Types Guide.

Any way. Thank you for responsibility.