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

[22041] Support setting and encoding options with least significant bits set with possible padding #244

Merged
merged 2 commits into from
Nov 5, 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
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
Loading