What is the max. number of octets I can put into the topic_data for builtin topics?

As described in the online HTML documentation for the DomainParticipantResourceLimits Qos Policy, there is a QoS parameter called  topic_data_max_length, which is used to set the maximum length of the topic data to be sent out. 

topic_data_max_length is a DDS_Long, which is a 32-bit signed long integer value with a valid range from 0 to 0x7fffffff. By default, the maximum length is 256, which corresponds to bytes. Since a DDS_Octet is equivalent to 1 Byte (8bits), then when using the defaults, the maximum length you will be able to set is 256 octets. However, the maximum length allowed by RTI Data Distribution Service is 0x7fffffff, which in decimal is 2,147,483,647.

Here's an example using topic_data:

    char * topicDataValue = "This is topic_data content";
    len = strlen(topicDataValue) + 1;
    max = participant_qos.resource_limits.topic_data_max_length;

    if (len > max) {
        printf("error, topic_data exceeds resource limits\n");
    } else {
        // DDS_Octet is defined to be 8 bits. If chars are not 8 bits
        // on your system, this will not work.
        reinterpret_cast<const DDS_Octet*>(topicDataValue), len);

In this code snippet, we compare the result of  strlen() with participant_qos.resource_limits.topic_data_max_length. When using the defaults, if the 'len' value is greater than 256, you will see the message error, topic_data exceeds resource limits and you will get nothing in the topic_data field on the builtin reader of the other side.

If, for some reason, the maximum set on the QoS is exceeded nothing will be propagated nor truncated. As a consequence, you should expect the topic_data field on the other side to have a length of zero. You could verify this on the other side by using the on_data_available() callback:

    if (data_seq[i].topic_data.value.length() != 0) {
        printf("topic_data.value.length is != 0");
        topic_data = (char*)&data_seq[i].topic_data.value[0];
    } else {
        printf("topic_data.value.length is == 0");

Other Considerations 

  • If you increase the maximum number of octets as shown above, this change should also be made on the remote participants. 
  • Even though the maximum can be set to 2 billion, you must consider that sizes big enough to result in message fragmentation would be problematic.