Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Apr 8, 2020
1 parent 7ab017d commit a489c34
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
11 changes: 8 additions & 3 deletions rmw_cyclonedds_cpp/src/CDR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#ifndef ROS2_MASTER_CDR_HPP
#define ROS2_MASTER_CDR_HPP

#include <array>
#include <cstddef>
#include <cstdint>

#include "bytewise.hpp"
namespace rmw_cyclonedds_cpp
{
enum class EncodingVersion {
enum class EncodingVersion
{
CDR_Legacy,
CDR1,
CDR2,
Expand All @@ -32,7 +36,8 @@ struct DelimiterHeaderData
};

/// aka LC
enum class LengthCode {
enum class LengthCode
{
Bytes1 = 0,
Bytes2 = 1,
Bytes4 = 2,
Expand All @@ -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
{
Expand Down
28 changes: 17 additions & 11 deletions rmw_cyclonedds_cpp/src/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@

#include "CDR.hpp"
#include "CDRCursor.hpp"

namespace rmw_cyclonedds_cpp
{
class CDRReader : public AbstractCDRReader
{
protected:
std::unique_ptr<StructValueType> m_value_type;
CDREncodingInfo m_cdr;

public:
explicit CDRReader(std::unique_ptr<StructValueType> 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)
{
Expand Down Expand Up @@ -64,10 +68,12 @@ class CDRReader : public AbstractCDRReader
vt.assign(destination_object, static_cast<const uint16_t *>(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; i<vt.array_size(); i++) {
void * dest = byte_offset(destination_object,i*vt.element_value_type()->sizeof_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);
}
}
Expand All @@ -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; i<size; i++) {
void * dest = byte_offset(sequence_contents, i*vt.element_value_type()->sizeof_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);
}
}
Expand Down Expand Up @@ -123,4 +129,4 @@ class CDRReader : public AbstractCDRReader
}
}
};
} // namespace rmw_cyclonedds_cpp
} // namespace rmw_cyclonedds_cpp
9 changes: 7 additions & 2 deletions rmw_cyclonedds_cpp/src/Deserialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit a489c34

Please sign in to comment.