Accessing Sequence Max Length from DynamicData

2 posts / 0 new
Last post
mjg
Offline
Last seen: 4 months 2 weeks ago
Joined: 07/17/2024
Posts: 4
Accessing Sequence Max Length from DynamicData

Question: When receiving a sequence as a `DynamicData` object, how can I access the `_maximumLength` attribute?

Hello!

I am working on an RTI plugin that will receive messages as `DynamicData` and save it to a custom parquet format. These messages can be any structure/type and will be decoded on the fly to a flattened format.

The problem I am having is that there does not seem to be a way to access the maximum length attribute of a sequence member. However, I see in my debugger that there is an attribute (quite deeply nested) of the sequence `DynamicData` object that stores the `_maximumLength` value. Additionally, I can inspect the `member_info` of elements in the sequence and discover if they are populated or not. For this example, the `array` is a sequence of max length 3 with the first 2 values populated. (See images for debugger info.)

One solution is to try to access incremental element indices until an error is thrown, but this is hacky and also implies that the maximum length is known.

When receiving a sequence as a `DynamicData` object, how can I access the `_maximumLength` attribute? 

Thanks very much for your help!


Here is an example of the code that I am running:

 

```

void ParquetUtils::add_message_to_file(
dds::core::xtypes::DynamicData &message,
bool skip_end_row
) {

for (uint32_t i = 0; i < message.member_count(); i++) {

auto info = message.member_info(i + 1);
auto underlying_type = info.member_kind().underlying();

if(
underlying_type == dds::core::xtypes::TypeKind::ARRAY_TYPE ||
underlying_type == dds::core::xtypes::TypeKind::SEQUENCE_TYPE) {

auto loan = message.loan_value( i + 1);
dds::core::xtypes::DynamicData array = loan.get();

std::cout << "1 " << array.member_exists(1) << std::endl; // output: true
std::cout << "2 " << array.member_exists(2) << std::endl; // output: true
std::cout << "3 " << array.member_exists(3) << std::endl; // output: false
std::cout << "4 " << array.member_exists(4) << std::endl; // output: <caught exception> false

auto info1 = array.member_info(1);
auto info2 = array.member_info(2);
auto info3 = array.member_info(3);
// auto info4 = array.member_info(4); // throws exception

loan.return_loan();

}
}
if (!skip_end_row) {
end_row();
}
}

```

 

AttachmentSize
Image icon debugger_maximumLength1.52 MB
Image icon debugger_member_info496.17 KB
mjg
Offline
Last seen: 4 months 2 weeks ago
Joined: 07/17/2024
Posts: 4

SOLUTION:

Much thanks to RTI support for the guidance on this.

Here is the solution for a sequence:

DynamicData sample(mytype);
sample.value("my_sequence[0]", 33); // set the first element to 33 for example
auto loan = sample.loan_value("my_sequence");
dds::core::xtypes::DynamicData sequence = loan.get();
const SequenceType& mytype_seq = static_cast<const SequenceType&>(sequence.type());
std::cout << "Current is " << sequence.member_count() << std::endl; // will print 1, due to setting [0] to 33
std::cout << "Max elements is " << mytype_seq.bounds() << std::endl; // will print 10 

And for an array the solution would be:

auto loan = sample.loan_value("my_array");
dds::core::xtypes::DynamicData array = loan.get();
const ArrayType& mytype_arr = static_cast<const ArrayType&>(array.type());
std::cout << "Max elements is " << mytype_arr.dimension(0) << std::endl; // will print 5 

Cheers!