-
Notifications
You must be signed in to change notification settings - Fork 115
[23504] Optimize (de)serialization of flat, non-primitive arrays #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Mario Dominguez <[email protected]>
Signed-off-by: Mario Dominguez <[email protected]>
Signed-off-by: Mario Dominguez <[email protected]>
Signed-off-by: Mario Dominguez <[email protected]>
Signed-off-by: Mario Dominguez <[email protected]>
…TypesShortStruct Signed-off-by: Mario Dominguez <[email protected]>
c1a125a
to
8a54298
Compare
Signed-off-by: Mario Dominguez <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing signed versions of these tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing fixed_string
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments for all four declarations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialize(static_cast<int32_t>(vector_t.size())); | |
serialize(static_cast<uint32_t>(vector_t.size())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shall follow this same part in the XCDRv2 part of the if above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_array
template 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.md
file (if applicable).Reviewer Checklist