Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed May 1, 2020
1 parent 84045f8 commit bdf251a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
18 changes: 15 additions & 3 deletions rmw_cyclonedds_cpp/src/CDR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <cstddef>
#include <cstdint>


// https://www.omg.org/spec/DDS-XTypes/1.3/PDF
#include "bytewise.hpp"
namespace rmw_cyclonedds_cpp
{
Expand All @@ -18,21 +20,31 @@ enum class EncodingVersion
CDR2,
};

enum class EncodingType
{
PLAIN_CDR,
PL_CDR,
PLAIN_CDR2,
PL_CDR2,
DELIMIT_CDR,
XML,
};

/// aka ENC_HEADER
struct EncapsulationHeader
{
/// stream endianness
endian m_endian = native_endian();
/// encoding version
EncodingVersion m_eversion;
/// encoding type
EncodingType m_enc_type;
/// encoding options
std::array<byte, 2> m_options;
};

/// aka DHEADER
struct DelimiterHeaderData
{
int32_t size;
uint32_t size;
};

/// aka LC
Expand Down
11 changes: 10 additions & 1 deletion rmw_cyclonedds_cpp/src/Deserialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ namespace rmw_cyclonedds_cpp

void deserialize_top_level(void * destination_object, const void * data, const StructValueType * ts)
{
EncapsulationHeader enc_hdr; // todo
EncapsulationHeader enc_hdr;
auto bdata = static_cast<const byte *>(data);
uint16_t benc_hdr = (((uint16_t)data[0])<<8) | data[1];
enc_hdr.m_endian = (enc_hdr & 1) ? little_endian : big_endian;
switch(benc_hdr ) {
case 0x0000:
enc_hdr.m_endian
}
if (bdata[0] == 1)
enc_hdr.m_endian =
// todo: create deserialization stream using the encapsulation header (endian, eversion)
// todo: pull data out of that stream, structurally recursing on data and types
}
Expand Down
9 changes: 6 additions & 3 deletions rmw_cyclonedds_cpp/src/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ class CDRWriter : public AbstractCDRWriter
}

void serialize(
AbstractCDRWritingCursor * cursor, const void * data, const PrimitiveValueType & value_type) const
AbstractCDRWritingCursor * cursor, const void * data,
const PrimitiveValueType & value_type) const
{
cursor->align(get_cdr_alignof_primitive(value_type.type_kind()));
size_t n_bytes = get_cdr_size_of_primitive(value_type.type_kind());
Expand Down Expand Up @@ -385,7 +386,8 @@ class CDRWriter : public AbstractCDRWriter
}

void serialize(
AbstractCDRWritingCursor * cursor, const void * data, const U8StringValueType & value_type) const
AbstractCDRWritingCursor * cursor, const void * data,
const U8StringValueType & value_type) const
{
auto str = value_type.data(data);
serialize_u32(cursor, str.size() + 1);
Expand All @@ -395,7 +397,8 @@ class CDRWriter : public AbstractCDRWriter
}

void serialize(
AbstractCDRWritingCursor * cursor, const void * data, const U16StringValueType & value_type) const
AbstractCDRWritingCursor * cursor, const void * data,
const U16StringValueType & value_type) const
{
auto str = value_type.data(data);
if (eversion == EncodingVersion::CDR_Legacy) {
Expand Down
45 changes: 27 additions & 18 deletions rmw_cyclonedds_cpp/src/TypeSupport2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class StructValueType : public AnyValueType
virtual size_t n_members() const = 0;
virtual const Member * get_member(size_t) const = 0;
EValueType e_value_type() const final {return EValueType::StructValueType;}
virtual void ctor (void * obj) const = 0;
virtual void dtor (void * obj) const = 0;
virtual void ctor(void * obj) const = 0;
virtual void dtor(void * obj) const = 0;
};

class ArrayValueType : public AnyValueType
Expand Down Expand Up @@ -247,16 +247,17 @@ class ROSIDLCPP_SpanSequenceValueType : public SpanSequenceValueType
}
const void * sequence_contents(const void * ptr_to_sequence) const override
{
return nullptr;
return nullptr;
if (sequence_size(ptr_to_sequence) == 0) {
}
return m_message_member->get_const_function(ptr_to_sequence,0);
return m_message_member->get_const_function(ptr_to_sequence, 0);
}
void * sequence_contents(void * ptr_to_sequence) const override
{
return m_message_member->get_function(ptr_to_sequence, 0);
}
void resize(void * ptr_to_sequence, size_t new_size) const final {
void resize(void * ptr_to_sequence, size_t new_size) const final
{
m_message_member->resize_function(ptr_to_sequence, new_size);
}
};
Expand Down Expand Up @@ -284,10 +285,10 @@ class ROSIDLC_SpanSequenceValueType : public SpanSequenceValueType
return static_cast<ROSIDLC_SequenceObject *>(ptr_to_sequence);
}


public:
explicit ROSIDLC_SpanSequenceValueType(const rosidl_typesupport_introspection_c__MessageMember * message_member,
const AnyValueType * element_value_type)
explicit ROSIDLC_SpanSequenceValueType(
const rosidl_typesupport_introspection_c__MessageMember * message_member,
const AnyValueType * element_value_type)
: m_message_member(message_member),
m_element_value_type(element_value_type)
{
Expand All @@ -303,12 +304,14 @@ class ROSIDLC_SpanSequenceValueType : public SpanSequenceValueType
{
return get_value(ptr_to_sequence)->data;
}
void * sequence_contents(void * ptr_to_sequence) const final {
void * sequence_contents(void * ptr_to_sequence) const final
{
return get_value(ptr_to_sequence)->data;
}

void resize(void * ptr_to_sequence, size_t new_size) const final {
if (!m_message_member->resize_function(ptr_to_sequence, new_size)){
void resize(void * ptr_to_sequence, size_t new_size) const final
{
if (!m_message_member->resize_function(ptr_to_sequence, new_size)) {
throw std::runtime_error("Failed to resize");
}
}
Expand Down Expand Up @@ -446,7 +449,8 @@ struct ROSIDLC_StringValueType : public U8StringValueType
return {str->data, str->size};
}
size_t sizeof_type() const override {return sizeof(type);}
void assign(void * obj, const char * s, size_t count) const final {
void assign(void * obj, const char * s, size_t count) const final
{
rosidl_generator_c__String__assignn(static_cast<type *>(obj), s, count);
}
};
Expand All @@ -467,8 +471,11 @@ class ROSIDLC_WStringValueType : public U16StringValueType
return {reinterpret_cast<char_traits::char_type *>(str->data), str->size};
}
size_t sizeof_type() const override {return sizeof(type);}
void assign(void * obj, const uint16_t * s, size_t count) const final {
rosidl_generator_c__U16String__assignn(static_cast<type *>(obj), static_cast<const uint16_t *>(s), count);
void assign(void * obj, const uint16_t * s, size_t count) const final
{
rosidl_generator_c__U16String__assignn(
static_cast<type *>(obj),
static_cast<const uint16_t *>(s), count);
}
};

Expand All @@ -489,8 +496,9 @@ class ROSIDLCPP_StringValueType : public U8StringValueType
}
size_t sizeof_type() const override {return sizeof(type);}

void assign(void * obj, const char * s, size_t count) const final {
static_cast<type *>(obj)->assign(s,count);
void assign(void * obj, const char * s, size_t count) const final
{
static_cast<type *>(obj)->assign(s, count);
}
};

Expand All @@ -510,11 +518,12 @@ class ROSIDLCPP_U16StringValueType : public U16StringValueType
return {str->data(), str->size()};
}
size_t sizeof_type() const override {return sizeof(type);}
void assign(void * obj, const uint16_t * s, size_t count) const final {
void assign(void * obj, const uint16_t * s, size_t count) const final
{
// std::u16string x;
// uint16_t * y;
// x.assign(y,y+4);
static_cast<type *>(obj)->assign(s,s+count);
static_cast<type *>(obj)->assign(s, s + count);
}
};

Expand Down

0 comments on commit bdf251a

Please sign in to comment.