diff --git a/rmw_cyclonedds_cpp/src/CDR.hpp b/rmw_cyclonedds_cpp/src/CDR.hpp index 92a5612d..485cdca9 100644 --- a/rmw_cyclonedds_cpp/src/CDR.hpp +++ b/rmw_cyclonedds_cpp/src/CDR.hpp @@ -4,11 +4,15 @@ #ifndef ROS2_MASTER_CDR_HPP #define ROS2_MASTER_CDR_HPP +#include #include #include + +#include "bytewise.hpp" namespace rmw_cyclonedds_cpp { -enum class EncodingVersion { +enum class EncodingVersion +{ CDR_Legacy, CDR1, CDR2, @@ -32,7 +36,8 @@ struct DelimiterHeaderData }; /// aka LC -enum class LengthCode { +enum class LengthCode +{ Bytes1 = 0, Bytes2 = 1, Bytes4 = 2, @@ -56,7 +61,7 @@ class CDREncodingInfo EncodingVersion m_version; public: - explicit CDREncodingInfo(EncodingVersion version) { m_version = version; } + explicit CDREncodingInfo(EncodingVersion version) {m_version = version;} size_t max_align() const { diff --git a/rmw_cyclonedds_cpp/src/Deserialization.cpp b/rmw_cyclonedds_cpp/src/Deserialization.cpp index 1c76a09a..2d4156e4 100644 --- a/rmw_cyclonedds_cpp/src/Deserialization.cpp +++ b/rmw_cyclonedds_cpp/src/Deserialization.cpp @@ -15,22 +15,26 @@ #include "CDR.hpp" #include "CDRCursor.hpp" + namespace rmw_cyclonedds_cpp { class CDRReader : public AbstractCDRReader { protected: + std::unique_ptr m_value_type; CDREncodingInfo m_cdr; public: explicit CDRReader(std::unique_ptr value_type) - : m_cdr{EncodingVersion::CDR_Legacy} - { - std::ignore = (value_type); //todo - } + : m_cdr{EncodingVersion::CDR_Legacy}, + m_value_type{std::move(value_type)} + {} void deserialize_top_level( - void * destination_object, const void * data, const StructValueType * ts); + void * destination_object, const void * data, const StructValueType * ts) + { + + } uint32_t read_u32(CDRReadCursor * data_cursor) { @@ -64,10 +68,12 @@ class CDRReader : public AbstractCDRReader vt.assign(destination_object, static_cast(data_cursor->position), size); } - void deserialize(void * destination_object, const ArrayValueType & vt, CDRReadCursor * data_cursor) + void deserialize( + void * destination_object, const ArrayValueType & vt, + CDRReadCursor * data_cursor) { - for (size_t i=0; isizeof_type()); + for (size_t i = 0; i < vt.array_size(); i++) { + void * dest = byte_offset(destination_object, i * vt.element_value_type()->sizeof_type()); deserialize(dest, vt.element_value_type(), data_cursor); } } @@ -78,8 +84,8 @@ class CDRReader : public AbstractCDRReader size_t size = read_u32(data_cursor); vt.resize(destination_object, size); void * sequence_contents = vt.sequence_contents(destination_object); - for (size_t i=0; isizeof_type()); + for (size_t i = 0; i < size; i++) { + void * dest = byte_offset(sequence_contents, i * vt.element_value_type()->sizeof_type()); deserialize(dest, vt.element_value_type(), data_cursor); } } @@ -123,4 +129,4 @@ class CDRReader : public AbstractCDRReader } } }; -} // namespace rmw_cyclonedds_cpp \ No newline at end of file +} // namespace rmw_cyclonedds_cpp diff --git a/rmw_cyclonedds_cpp/src/Deserialization.hpp b/rmw_cyclonedds_cpp/src/Deserialization.hpp index 753a0ae3..e6b442a3 100644 --- a/rmw_cyclonedds_cpp/src/Deserialization.hpp +++ b/rmw_cyclonedds_cpp/src/Deserialization.hpp @@ -14,13 +14,18 @@ #ifndef ROS2_MASTER_DESERIALIZATION_HPP #define ROS2_MASTER_DESERIALIZATION_HPP +#include "CDR.hpp" #include "TypeSupport2.hpp" #include "serdata.hpp" namespace rmw_cyclonedds_cpp { -void deserialize_top_level( - void * destination_object, const void * data, const StructValueType * ts); +void deserialize_top_level(void * destination_object, const void * data, const StructValueType * ts) +{ + EncapsulationHeader enc_hdr; // todo + // todo: create deserialization stream using the encapsulation header (endian, eversion) + // todo: pull data out of that stream, structurally recursing on data and types +} class AbstractCDRReader {