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();
}
}
```
Attachment | Size |
---|---|
![]() | 1.52 MB |
![]() | 496.17 KB |
SOLUTION:
Much thanks to RTI support for the guidance on this.
Here is the solution for a sequence:
And for an array the solution would be:
Cheers!