Hello!
UPDATE: I had a copy paste mistake in my tests when I was looking for a right method to get serialized size of dynamic data. I've updated post correctly. Function works as it should, however I still don't understand the meaning of the values.
One of DDS usecases involves serializing and deserializing DynamicData objects. I was looking for a method to get size of serialized representation and DDS_DynamicData_get_serialized_size
looked like good guess, but it seems that there is something strange problem with this method. According to the source code of this function, it makes nothing else but calls DDS_DynamicData_get_serialized_size_ex
(if self->_buffer.parametrizedBuffer
== 0 and it's my case) so my expectation was that both functions provide the same result. As another solution to get size I've found another method - DDS_DynamicDataBuffer_get_data_size
. I've made tests with two typecodes - one with constant size and another with sequence. As expected value I've took RTICdrStream_getCurrentPositionOffset()
after calling DDS_DynamicData_to_stream()
Constant sized type:
- serialized_min_size/serialized_max_size: 568/568
- DDS_DynamicData_get_serialized_size: 1136
- DDS_DynamicData_get_serialized_size_ex (last parameter set to FALSE): 568
- DDS_DynamicData_get_serialized_size_ex (last parameter set to TRUE, as in source code): 1136
- DDS_DynamicDataBuffer_get_data_size: 568
- Expected value: 568
Type with sequence:
- serialized_min_size/serialized_max_size: 20/10000020
- DDS_DynamicData_get_serialized_size: 1040
- DDS_DynamicData_get_serialized_size_ex (last parameter set to FALSE): 1020
- DDS_DynamicData_get_serialized_size_ex (last parameter set to TRUE, as in source code): 1040
- DDS_DynamicDataBuffer_get_data_size: 1020
- Expected value: 1020
Hi,
The meaning of those various values are as follows:
Also, where are the values for serialized_min_size/serialized_max_size comine from?
Please let me know if any of that is not clear.
Thank you for your explanation! Could you give some more details about parameter header?
min/max sizes are coming from these private functions:
unsigned int
DDS_TypeCode_get_type_serialized_max_size
(const DDS_TypeCode *type, RTIBool include_encapsulation, /* ignored */ RTIEncapsulationId encapsulation_id, unsigned int current_alignment);unsigned int
DDS_TypeCode_get_type_serialized_min_size
(const DDS_TypeCode *type, RTIBool include_encapsulation, RTIEncapsulationId encapsulation_id, unsigned int current_alignment, DDS_Boolean use_default_union_member);You're welcome!
There is a good explanation of what exactly goes on the wire in the RTI_CoreLibrariesAndUtilitie_GettingStarted_ExtensibleTypesAddendum.pdf in you NDDSHOME/doc/pdf directory, Chapter 4 "DataRepresentation". To summarize though, in the case of final and extensible types, we use the traditional OMG CDR representation ot serialize the data (no parameter header), but in the case of optional members and mutable types we use Extended CDR (an extension to the OMG CDR representation), which is when the parameter header gets used. So yes, there is extra over head when sending mutable data or data with optional members.
It would help me to understand what's going on if you could tell me the exact types that your using in these two scenarios, but yes--the DDS_DynamicData_get_serialized_size will return a conservative number, including room for the parameter header that may need to be added in the case of mutable types or the existence of optional members in your type.
The types are:
RTI Admin Console shows that struct struct1 is extensible, field data is mutable, remaining fields are final. struct2 itself is extensible, all members are final.
Thanks for pointing to the ExtensibleTypesAddendum, it explains appending header quite well, but I think it's little confusing that
get_serialized_size
always returns size with parameter header even if it's not needed. I think the solution is to use logic fromDDS_DynamicDataTypePlugin_get_serialized_sample_size
and call