Published string array is received with null values

3 posts / 0 new
Last post
Offline
Last seen: 10 years 12 months ago
Joined: 09/17/2013
Posts: 10
Published string array is received with null values

Hi guys,

I am kind of newbie in this DDS. I am trying to publish a topic data with a string array inside, but it doesn't work for me. In detail, I have the IDL struct to be:

const long LABEL_MAX_LEN=128;
typedef string<LABEL_MAX_LEN> Label;

const long MAX_LABELS=64;

struct StructWithSequences {
    Label smaple_test;
    sequence<Label, MAX_LABELS> labels;
};

 

Just before to publish I can see that the labels array is filled with string values. In the QoS profile I have it set up to be TRANSIENT_DURABILITY_QOS. After I publish I can see that the sample_test variable is exactly what I published, but the labels array consists of 64 null values. So, all my string values disappeared somewhere on the way and they turned into null values. Again, pay attention on the fact that it is exactly the topic data that I published since the sample_test value is the one that I published, only the array values turn into nulls.

I appreciate any help, any comments.

Thanks in advance.

Offline
Last seen: 8 months 5 days ago
Joined: 06/13/2013
Posts: 17

How are you setting the label values in the code? Would it be possible for you to provide the code example? Are you setting the length of the sequence to the number of labels you have?

Andre

Offline
Last seen: 10 years 12 months ago
Joined: 09/17/2013
Posts: 10

I found the solution. No matter you have the maximum size declared in the IDL file, you have to programmatically call the ensure_length method of the array field then to fill the values. The memory is allocated anyway, you can assign your values, but after the transfer the array elements are set to null, but if before publishment and assignement you call the ensure_length method then after the transfer you will have all your assigned values properly delivered. Thanks anyway.