Skip to content

Commit

Permalink
Support setting and encoding options with least significant bits set …
Browse files Browse the repository at this point in the history
…with possible padding (#244)

* Refs #22039. Support serializing options

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #22039. Add test

Signed-off-by: Ricardo González Moreno <[email protected]>

---------

Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware authored Nov 5, 2024
1 parent b7110b4 commit f4d99fe
Show file tree
Hide file tree
Showing 10 changed files with 744 additions and 526 deletions.
6 changes: 6 additions & 0 deletions include/fastcdr/Cdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3548,6 +3548,12 @@ class Cdr
//! Specifies if a DHEADER was serialized. Used to optimize XCDRv2 member headers.
serialized_member_size_ {NO_SERIALIZED_MEMBER_SIZE};

//! Stores the initial state.
state initial_state_;

//! Whether the encapsulation was serialized.
bool encapsulation_serialized_ {false};


uint32_t get_long_lc(
SerializedMemberSizeForNextInt serialized_member_size);
Expand Down
35 changes: 35 additions & 0 deletions src/cpp/Cdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Cdr::Cdr(
, offset_(cdr_buffer.begin())
, origin_(cdr_buffer.begin())
, end_(cdr_buffer.end())
, initial_state_(*this)
{
switch (cdr_version_)
{
Expand Down Expand Up @@ -272,7 +273,21 @@ Cdr& Cdr::read_encapsulation()
if (CdrVersion::CORBA_CDR < cdr_version_)
{
deserialize(options_);

uint8_t option_align {static_cast<uint8_t>(options_[1] & 0x3u)};

if (0 < option_align)
{
auto length {end_ - cdr_buffer_.begin()};
auto alignment = ((length + 3u) & ~3u) - length;

if (0 == alignment)
{
end_ -= option_align;
}
}
}

}
catch (Exception& ex)
{
Expand Down Expand Up @@ -326,6 +341,7 @@ Cdr& Cdr::serialize_encapsulation()
}

reset_alignment();
encapsulation_serialized_ = true;
return *this;
}

Expand Down Expand Up @@ -365,6 +381,25 @@ void Cdr::set_dds_cdr_options(
const std::array<uint8_t, 2>& options)
{
options_ = options;

if (CdrVersion::XCDRv1 == cdr_version_ ||
CdrVersion::XCDRv2 == cdr_version_)
{
auto length {offset_ - cdr_buffer_.begin()};
auto alignment = ((length + 3u) & ~3u) - length;
options_[1] = static_cast<uint8_t>(options_[1] & 0xC) + static_cast<uint8_t>(alignment & 0x3);
}

if (encapsulation_serialized_ && CdrVersion::CORBA_CDR < cdr_version_)
{
state previous_state(*this);
set_state(initial_state_);

jump(2);
serialize(options_);

set_state(previous_state);
}
}

void Cdr::change_endianness(
Expand Down
Loading

0 comments on commit f4d99fe

Please sign in to comment.