[23504] Optimize (de)serialization of flat, non-primitive arrays#274
[23504] Optimize (de)serialization of flat, non-primitive arrays#274
Conversation
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
…TypesShortStruct Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
c1a125a to
8a54298
Compare
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
MiguelCompany
left a comment
There was a problem hiding this comment.
Very nice refactor!
I really like the traits and SFINAE being used.
Leaving some comments
| static_assert(static_is_multi_array_primitive<uint8_t const*>::value, "uint8_t* should be a multi primitive array"); | ||
| static_assert(static_is_multi_array_primitive<uint16_t const*>::value, | ||
| "uint16_t* should be a multi primitive array"); | ||
| static_assert(static_is_multi_array_primitive<uint32_t const*>::value, | ||
| "uint32_t* should be a multi primitive array"); | ||
| static_assert(static_is_multi_array_primitive<uint64_t const*>::value, | ||
| "uint64_t* should be a multi primitive array"); |
There was a problem hiding this comment.
Missing signed versions of these tests
There was a problem hiding this comment.
Also missing tests for enum
| static_assert(!static_is_multi_array_primitive<std::string const*>::value, | ||
| "std::string* should not be a multi primitive array"); |
| template<class _T> | ||
| extern void serialize_array( | ||
| Cdr&, | ||
| const _T*, | ||
| const size_t); | ||
|
|
||
| template<class _T> | ||
| extern void deserialize_array( | ||
| Cdr&, | ||
| _T*, | ||
| const size_t); | ||
|
|
There was a problem hiding this comment.
Add comments for all four declarations
There was a problem hiding this comment.
Also change the declaration order. Either serialize, deserialize, serialize_array, deserialize_array or serialize, serialize_array, deserialize, deserialize_array
| Cdr& serialize( | ||
| const std::array<_T, _Size>& array_t) | ||
| { | ||
| if (!is_multi_array_primitive(&array_t)) |
There was a problem hiding this comment.
Seems is_multi_array_primitive is not used anymore (since we now rely on static_is_multi_array_primitive).
Might be a good idea to remove file container_recursive_inspector.hpp and perhaps also rename static_is_multi_array_primitive into is_multi_array_primitive.
| Cdr::state dheader_state {allocate_xcdrv2_dheader()}; | ||
|
|
||
| serialize_array(array_t.data(), array_t.size()); | ||
| serialize(static_cast<int32_t>(vector_t.size())); |
There was a problem hiding this comment.
| serialize(static_cast<int32_t>(vector_t.size())); | |
| serialize(static_cast<uint32_t>(vector_t.size())); |
There was a problem hiding this comment.
We should check that the size is not bigger than the maximum value of a uint32_t.
I propose having a serialize_collection_length(size_t length) method that throws an exception when length > MAX_UINT32, and then serializes static_cast<uint32_t>(length).
There was a problem hiding this comment.
Note: this would imply changes in other methods unrelated to this PR. It might be a good idea to do that refactoring on a separate PR that we can backport.
| if ((end_ - offset_) < sequence_length) | ||
| { | ||
| set_state(state_before_error); | ||
| throw exception::NotEnoughMemoryException( | ||
| exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| vector_t.resize(sequence_length); | ||
| eprosima::fastcdr::deserialize_array(*this, vector_t.data(), vector_t.size()); | ||
| } | ||
| catch (exception::Exception& ex) | ||
| { | ||
| set_state(state_before_error); | ||
| ex.raise(); | ||
| } |
There was a problem hiding this comment.
We shall follow this same part in the XCDRv2 part of the if above.
There was a problem hiding this comment.
Again, this seems to come from the old code, so a separate PR fixing it that can be backported should be done.
Description
This PR makes Fast CDR look for external
(de)serialize_arraytemplate specializations (now provided by the generated types) so that flat, non-primitive arrays or vectors can be optimally serialized (memcpy) if certain conditions are met.These changes break API so must be in a new major release.
Related PRs:
Contributor Checklist
versions.mdfile (if applicable).Reviewer Checklist