Skip to content
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

[21785] Fix encoding/decoding when inner structure has different extensibility #237

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/fastcdr/CdrSizeCalculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ class CdrSizeCalculator
0 < calculated_size)
{

if (8 < calculated_size)
if (8 < calculated_size ||
(1 != calculated_size && 2 != calculated_size && 4 != calculated_size &&
8 != calculated_size))
{
extra_size = 8; // Long EMHEADER.
if (NO_SERIALIZED_MEMBER_SIZE != serialized_member_size_)
Expand Down
32 changes: 21 additions & 11 deletions src/cpp/Cdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ inline size_t alignment_on_state(
inline uint32_t Cdr::get_long_lc(
SerializedMemberSizeForNextInt serialized_member_size)
{
uint32_t lc = 0x40000000;
uint32_t lc {0x40000000};

switch (serialized_member_size)
{
case SERIALIZED_MEMBER_SIZE_8:
lc = 0x70000000;
lc = 0x70000000u;
break;
case SERIALIZED_MEMBER_SIZE_4:
lc = 0x60000000;
lc = 0x60000000u;
break;
case SERIALIZED_MEMBER_SIZE:
lc = 0x50000000;
lc = 0x50000000u;
break;
default:
break;
Expand All @@ -73,17 +73,20 @@ inline uint32_t Cdr::get_long_lc(
inline uint32_t Cdr::get_short_lc(
size_t member_serialized_size)
{
uint32_t lc = 0x0;
uint32_t lc {0xFFFFFFFFu};
switch (member_serialized_size)
{
case 1:
lc = 0x00000000u;
break;
case 2:
lc = 0x10000000;
lc = 0x10000000u;
break;
case 4:
lc = 0x20000000;
lc = 0x20000000u;
break;
case 8:
lc = 0x30000000;
lc = 0x30000000u;
break;
default:
break;
Expand Down Expand Up @@ -2986,7 +2989,7 @@ Cdr& Cdr::xcdr2_end_serialize_member(
{
const size_t member_serialized_size = last_offset - offset_ -
(current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 8);
if (8 < member_serialized_size)
if (8 < member_serialized_size || 0xFFFFFFFFu == get_short_lc(member_serialized_size))
{
switch (current_state.header_serialized_)
{
Expand Down Expand Up @@ -3196,8 +3199,9 @@ Cdr& Cdr::xcdr1_deserialize_type(
assert(EncodingAlgorithmFlag::PLAIN_CDR == type_encoding ||
EncodingAlgorithmFlag::PL_CDR == type_encoding);
Cdr::state current_state(*this);
current_encoding_ = type_encoding;

if (EncodingAlgorithmFlag::PL_CDR == type_encoding)
if (EncodingAlgorithmFlag::PL_CDR == current_encoding_)
{
while (xcdr1_deserialize_member_header(next_member_id_, current_state))
{
Expand Down Expand Up @@ -3234,6 +3238,7 @@ Cdr& Cdr::xcdr1_deserialize_type(
}

next_member_id_ = current_state.next_member_id_;
current_encoding_ = current_state.previous_encoding_;

return *this;
}
Expand All @@ -3253,8 +3258,9 @@ Cdr& Cdr::xcdr2_deserialize_type(
deserialize(dheader);

Cdr::state current_state(*this);
current_encoding_ = type_encoding;

if (EncodingAlgorithmFlag::PL_CDR2 == type_encoding)
if (EncodingAlgorithmFlag::PL_CDR2 == current_encoding_)
{
while (offset_ - current_state.offset_ != dheader)
{
Expand Down Expand Up @@ -3306,10 +3312,13 @@ Cdr& Cdr::xcdr2_deserialize_type(

next_member_id_ = current_state.next_member_id_;
}

current_encoding_ = current_state.previous_encoding_;
}
else
{
Cdr::state current_state(*this);
current_encoding_ = type_encoding;
next_member_id_ = MemberId(0);

while (offset_ != end_ && functor(*this, next_member_id_))
Expand All @@ -3318,6 +3327,7 @@ Cdr& Cdr::xcdr2_deserialize_type(
}

next_member_id_ = current_state.next_member_id_;
current_encoding_ = current_state.previous_encoding_;
}

return *this;
Expand Down
1 change: 1 addition & 0 deletions test/xcdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(XCDR_TEST_SOURCE
appendable.cpp
basic_types.cpp
external.cpp
final.cpp
mutable.cpp
optional.cpp
xcdrv1.cpp
Expand Down
Loading
Loading