Proper way to set char array in RTI DDS Connector

3 posts / 0 new
Last post
Offline
Last seen: 4 years 1 week ago
Joined: 03/31/2019
Posts: 3
Proper way to set char array in RTI DDS Connector

I'm using a type within the DDS Connector which features a char[256] array intended to represent a string. I'd like to be able to write this field properly from the python connector without having to change the base generated type to the standard DDS String (this would necessitate large changes in our codebase).

Effectively, I'd like to be able to do the following from python:

myString = "sampleString"
output.instance.set_string("charArrayFieldName", myString);

Where charArrayFieldName is defined as a 256 element char array as follows in the generated XML:

<member name="charArrayFieldName" type="char8" arrayDimensions="256"/>

Is there any easy way to do this with the python connector? Using set_string throws an obvious error since the written type isn't actually a DDS String.

Thank you,
jmont723

Offline
Last seen: 1 year 1 month ago
Joined: 10/22/2018
Posts: 91

Hi,

You can use the set_dictionary API to do this as follows:

output.instance.set_dictionary({"charArrayFieldName": ['h', 'e', 'l', 'l', 'o']})

But you should first read the relevant section of the documentation here, as it explains that you will likely have to use the  clear_member API inbetween writes.

Sam

Offline
Last seen: 4 years 1 week ago
Joined: 03/31/2019
Posts: 3

Thanks samr, this was helpful. We're also going to make the switch over to DDS Strings when possible to just to make life easier in the future. This will suffice for now though.