diff --git a/rmw_cyclonedds_cpp/src/CDR.hpp b/rmw_cyclonedds_cpp/src/CDR.hpp index 485cdca9..cdc2982f 100644 --- a/rmw_cyclonedds_cpp/src/CDR.hpp +++ b/rmw_cyclonedds_cpp/src/CDR.hpp @@ -8,6 +8,8 @@ #include #include + +// https://www.omg.org/spec/DDS-XTypes/1.3/PDF #include "bytewise.hpp" namespace rmw_cyclonedds_cpp { @@ -18,13 +20,23 @@ 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 m_options; }; @@ -32,7 +44,7 @@ struct EncapsulationHeader /// aka DHEADER struct DelimiterHeaderData { - int32_t size; + uint32_t size; }; /// aka LC diff --git a/rmw_cyclonedds_cpp/src/Deserialization.hpp b/rmw_cyclonedds_cpp/src/Deserialization.hpp index e6b442a3..4be94d60 100644 --- a/rmw_cyclonedds_cpp/src/Deserialization.hpp +++ b/rmw_cyclonedds_cpp/src/Deserialization.hpp @@ -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(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 } diff --git a/rmw_cyclonedds_cpp/src/Serialization.cpp b/rmw_cyclonedds_cpp/src/Serialization.cpp index f8d67312..e44bd424 100644 --- a/rmw_cyclonedds_cpp/src/Serialization.cpp +++ b/rmw_cyclonedds_cpp/src/Serialization.cpp @@ -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()); @@ -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); @@ -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) { diff --git a/rmw_cyclonedds_cpp/src/TypeSupport2.hpp b/rmw_cyclonedds_cpp/src/TypeSupport2.hpp index e8526804..a97019eb 100644 --- a/rmw_cyclonedds_cpp/src/TypeSupport2.hpp +++ b/rmw_cyclonedds_cpp/src/TypeSupport2.hpp @@ -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 @@ -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); } }; @@ -284,10 +285,10 @@ class ROSIDLC_SpanSequenceValueType : public SpanSequenceValueType return static_cast(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) { @@ -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"); } } @@ -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(obj), s, count); } }; @@ -467,8 +471,11 @@ class ROSIDLC_WStringValueType : public U16StringValueType return {reinterpret_cast(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(obj), static_cast(s), count); + void assign(void * obj, const uint16_t * s, size_t count) const final + { + rosidl_generator_c__U16String__assignn( + static_cast(obj), + static_cast(s), count); } }; @@ -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(obj)->assign(s,count); + void assign(void * obj, const char * s, size_t count) const final + { + static_cast(obj)->assign(s, count); } }; @@ -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(obj)->assign(s,s+count); + static_cast(obj)->assign(s, s + count); } };