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

Fix deserialization endianness #336

Merged
merged 3 commits into from
Jul 25, 2023
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
7 changes: 7 additions & 0 deletions include/uxr/agent/message/InputMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ inline bool InputMessage::prepare_next_submessage()
if (fastbuffer_.getBufferSize() > deserializer_.getSerializedDataLength())
{
rv = deserialize(subheader_);

// Check submessage endianness
fastcdr::Cdr::Endianness endianness = static_cast<fastcdr::Cdr::Endianness>(subheader_.flags() & 0x01);
if (endianness != deserializer_.endianness())
{
deserializer_.changeEndianness(endianness);
}
}
return rv;
}
Expand Down
81 changes: 78 additions & 3 deletions include/uxr/agent/types/XRCETypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ const XrceVersion XRCE_VERSION = {XRCE_VERSION_MAJOR, XRCE_VERSION_MINOR};
const uint8_t XRCE_VENDOR_INVALID1 = 0x00;
const uint8_t XRCE_VENDOR_INVALID2 = 0x00;

//! @brief This enumeration represents the two posible values of the SubMessage endianness flag.
typedef enum Endianness
{
//! @brief Big endianness.
BIG_ENDIANNESS = 0x0,
//! @brief Little endianness.
LITTLE_ENDIANNESS = 0x1
} Endianness;

/*!
* @brief This class represents the structure Time_t defined by the user in the IDL file.
* @ingroup TYPESMOD
Expand Down Expand Up @@ -2364,6 +2373,24 @@ class OBJK_RepresentationBinAndXML_Base
return m_representation;
}

/*!
* @brief This function updates the value in representation endianness
* @param endianness New value of representation endianness
*/
inline void endianness(Endianness endianness)
{
m_endianness = endianness;
}

/*!
* @brief This function returns a copy to the representation endianness
* @return Representation endianness
*/
inline Endianness endianness() const
{
return m_endianness;
}

/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
Expand Down Expand Up @@ -2395,6 +2422,7 @@ class OBJK_RepresentationBinAndXML_Base

private:
OBJK_RepresentationBinAndXMLFormats m_representation;
Endianness m_endianness;
};

/*!
Expand Down Expand Up @@ -2474,7 +2502,25 @@ class OBJK_Representation3_Base
{
return m_representation;
}


/*!
* @brief This function updates the value in representation endianness
* @param endianness New value of representation endianness
*/
inline void endianness(Endianness endianness)
{
m_endianness = endianness;
}

/*!
* @brief This function returns a copy to the representation endianness
* @return Representation endianness
*/
inline Endianness endianness() const
{
return m_endianness;
}

/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
Expand Down Expand Up @@ -2505,6 +2551,7 @@ class OBJK_Representation3_Base

private:
OBJK_Representation3Formats m_representation;
Endianness m_endianness;
};

/*!
Expand Down Expand Up @@ -5902,7 +5949,34 @@ class ObjectVariant
* @exception dds::xrce::XRCETypesException This exception is thrown if the requested union member is not the current selection.
*/
REPLIER_Representation& replier();


/*!
* @brief This function updates the value in representation endianness
* @param endianness New value of representation endianness
*/
inline void endianness(Endianness endianness)
{
m_endianness = endianness;

m_participant.endianness(m_endianness);
m_topic.endianness(m_endianness);
m_publisher.endianness(m_endianness);
m_subscriber.endianness(m_endianness);
m_data_writer.endianness(m_endianness);
m_data_reader.endianness(m_endianness);
m_requester.endianness(m_endianness);
m_replier.endianness(m_endianness);
}

/*!
* @brief This function returns a copy to the representation endianness
* @return Representation endianness
*/
inline Endianness endianness() const
{
return m_endianness;
}

/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
Expand Down Expand Up @@ -5933,7 +6007,8 @@ class ObjectVariant

private:
ObjectKind m__d;

Endianness m_endianness;

AGENT_Representation m_agent;
CLIENT_Representation m_client;
OBJK_APPLICATION_Representation m_application;
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/datareader/DataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ std::unique_ptr<DataReader> DataReader::create(
dds::xrce::OBJK_DataReader_Binary datareader_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
datareader_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_datareader_by_bin(raw_object_id, subscriber_id, datareader_xrce);
Expand Down Expand Up @@ -111,7 +112,8 @@ bool DataReader::matched(
dds::xrce::OBJK_DataReader_Binary datareader_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
datareader_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_datareader_from_bin(get_raw_id(), datareader_xrce);
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/datawriter/DataWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ std::unique_ptr<DataWriter> DataWriter::create(
dds::xrce::OBJK_DataWriter_Binary datawriter_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
datawriter_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_datawriter_by_bin(raw_object_id, publisher_id, datawriter_xrce);
Expand Down Expand Up @@ -105,7 +106,8 @@ bool DataWriter::matched(const dds::xrce::ObjectVariant& new_object_rep) const
dds::xrce::OBJK_DataWriter_Binary datawriter_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
datawriter_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_datawriter_from_bin(get_raw_id(), datawriter_xrce);
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/participant/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ std::unique_ptr<Participant> Participant::create(
participant_xrce.domain_id(representation.domain_id());

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
participant_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_participant_by_bin(raw_object_id, participant_xrce);
Expand Down Expand Up @@ -106,7 +107,8 @@ bool Participant::matched(const dds::xrce::ObjectVariant& new_object_rep) const
participant_xrce.domain_id(domain_id);

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
participant_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_participant_from_bin(get_raw_id(), domain_id, participant_xrce);
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/processor/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ bool Processor<EndPoint>::process_create_submessage(
dds::xrce::CREATE_Payload create_payload;
if (input_packet.message->get_payload(create_payload))
{
dds::xrce::Endianness endianness = static_cast<dds::xrce::Endianness>(input_packet.message->get_subheader().flags() & 0x01);
create_payload.object_representation().endianness(endianness);

dds::xrce::STATUS_Payload status_payload;
status_payload.related_request().request_id(create_payload.request_id());
status_payload.related_request().object_id(create_payload.object_id());
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/publisher/Publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ std::unique_ptr<Publisher> Publisher::create(
dds::xrce::OBJK_Publisher_Binary publisher_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
publisher_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_publisher_by_bin(raw_object_id, participant_id, publisher_xrce);
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/replier/Replier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ std::unique_ptr<Replier> Replier::create(
dds::xrce::OBJK_Replier_Binary replier_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
replier_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_replier_by_bin(raw_object_id, participant_id, replier_xrce);
Expand Down Expand Up @@ -108,7 +109,8 @@ bool Replier::matched(
dds::xrce::OBJK_Replier_Binary replier_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
replier_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_replier_from_bin(get_raw_id(), replier_xrce);
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/requester/Requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ std::unique_ptr<Requester> Requester::create(
dds::xrce::OBJK_Requester_Binary request_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
request_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_requester_by_bin(raw_object_id, participant_id, request_xrce);
Expand Down Expand Up @@ -110,7 +111,8 @@ bool Requester::matched(
dds::xrce::OBJK_Requester_Binary request_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
request_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_requester_from_bin(get_raw_id(), request_xrce);
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/subscriber/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ std::unique_ptr<Subscriber> Subscriber::create(
dds::xrce::OBJK_Subscriber_Binary subscriber_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
subscriber_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_subscriber_by_bin(raw_object_id, participant_id, subscriber_xrce);
Expand Down
6 changes: 4 additions & 2 deletions src/cpp/topic/Topic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ std::unique_ptr<Topic> Topic::create(
dds::xrce::OBJK_Topic_Binary topic_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(representation.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
topic_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_topic_by_bin(raw_object_id, participant_id, topic_xrce);
Expand Down Expand Up @@ -103,7 +104,8 @@ bool Topic::matched(const dds::xrce::ObjectVariant& new_object_rep) const
dds::xrce::OBJK_Topic_Binary topic_xrce;

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
eprosima::fastcdr::Cdr::Endianness endianness = static_cast<eprosima::fastcdr::Cdr::Endianness>(new_object_rep.endianness());
eprosima::fastcdr::Cdr cdr(fastbuffer, endianness);
topic_xrce.deserialize(cdr);

rv = proxy_client_->get_middleware().matched_topic_from_bin(get_raw_id(), topic_xrce);
Expand Down