Skip to content

Commit

Permalink
Support both fastcdr v1 and v2 (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm authored Dec 22, 2023
1 parent c74aec7 commit 208dadc
Show file tree
Hide file tree
Showing 11 changed files with 863 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.16.3)
cmake_minimum_required(VERSION 3.22)

project(AdvancedConfigurationExample VERSION 1 LANGUAGES CXX)

# Find requirements
if(NOT fastcdr_FOUND)
find_package(fastcdr REQUIRED)
find_package(fastcdr 2 REQUIRED)
endif()

if(NOT fastrtps_FOUND)
find_package(fastrtps REQUIRED)
find_package(fastrtps 2.12 REQUIRED)
endif()

#Check C++11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

/*!
* @file HelloWorld.cpp
* This source file contains the definition of the described types in the IDL file.
* This source file contains the implementation of the described types in the IDL file.
*
* This file was generated by the tool gen.
* This file was generated by the tool fastddsgen.
*/

#ifdef _WIN32
Expand All @@ -27,29 +27,26 @@ char dummy;
#endif // _WIN32

#include "HelloWorld.h"

#if FASTCDR_VERSION_MAJOR > 1

#include <fastcdr/Cdr.h>


#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;

#include <utility>

#define HelloWorld_max_cdr_typesize 24ULL;
#define HelloWorld_max_key_cdr_typesize 0ULL;



HelloWorld::HelloWorld()
{
// unsigned long m_index
m_index = 0;
// char m_message
memset(&m_message, 0, (20) * 1);

}

HelloWorld::~HelloWorld()
{


}

HelloWorld::HelloWorld(
Expand All @@ -72,7 +69,6 @@ HelloWorld& HelloWorld::operator =(

m_index = x.m_index;
m_message = x.m_message;

return *this;
}

Expand All @@ -82,15 +78,14 @@ HelloWorld& HelloWorld::operator =(

m_index = x.m_index;
m_message = std::move(x.m_message);

return *this;
}

bool HelloWorld::operator ==(
const HelloWorld& x) const
{

return (m_index == x.m_index && m_message == x.m_message);
return (m_index == x.m_index &&
m_message == x.m_message);
}

bool HelloWorld::operator !=(
Expand All @@ -99,49 +94,6 @@ bool HelloWorld::operator !=(
return !(*this == x);
}

size_t HelloWorld::getMaxCdrSerializedSize(
size_t current_alignment)
{
static_cast<void>(current_alignment);
return HelloWorld_max_cdr_typesize;
}

size_t HelloWorld::getCdrSerializedSize(
const HelloWorld& data,
size_t current_alignment)
{
(void)data;
size_t initial_alignment = current_alignment;


current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);


current_alignment += ((20) * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);


return current_alignment - initial_alignment;
}

void HelloWorld::serialize(
eprosima::fastcdr::Cdr& scdr) const
{

scdr << m_index;
scdr << m_message;


}

void HelloWorld::deserialize(
eprosima::fastcdr::Cdr& dcdr)
{

dcdr >> m_index;
dcdr >> m_message;

}

/*!
* @brief This function sets a value in member index
* @param _index New value for member index
Expand Down Expand Up @@ -170,6 +122,7 @@ uint32_t& HelloWorld::index()
return m_index;
}


/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
Expand Down Expand Up @@ -208,20 +161,8 @@ std::array<char, 20>& HelloWorld::message()
return m_message;
}

size_t HelloWorld::getKeyMaxCdrSerializedSize(
size_t current_alignment)
{
static_cast<void>(current_alignment);
return HelloWorld_max_key_cdr_typesize;
}

bool HelloWorld::isKeyDefined()
{
return false;
}
// Include auxiliary functions like for serializing/deserializing.
#include "HelloWorldCdrAux.ipp"

void HelloWorld::serializeKey(
eprosima::fastcdr::Cdr& scdr) const
{
(void) scdr;
}
#endif // FASTCDR_VERSION_MAJOR > 1
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@
* @file HelloWorld.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
* This file was generated by the tool fastddsgen.
*/

#ifndef _FAST_DDS_GENERATED_HELLOWORLD_H_
#define _FAST_DDS_GENERATED_HELLOWORLD_H_
#include <fastcdr/config.h>
#include "HelloWorldv1.h"

#if FASTCDR_VERSION_MAJOR > 1

#include <fastrtps/utils/fixed_size_string.hpp>
#ifndef _FAST_DDS_GENERATED_HELLOWORLD_H_
#define _FAST_DDS_GENERATED_HELLOWORLD_H_

#include <stdint.h>
#include <array>
#include <bitset>
#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include <map>
#include <bitset>

#include <fastcdr/cdr/fixed_size_string.hpp>
#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>



#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
Expand Down Expand Up @@ -59,10 +67,14 @@
namespace eprosima {
namespace fastcdr {
class Cdr;
class CdrSizeCalculator;
} // namespace fastcdr
} // namespace eprosima





/*!
* @brief This class represents the structure HelloWorld defined by the user in the IDL file.
* @ingroup HelloWorld
Expand Down Expand Up @@ -142,6 +154,7 @@ class HelloWorld
*/
eProsima_user_DllExport uint32_t& index();


/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
Expand All @@ -168,69 +181,15 @@ class HelloWorld
*/
eProsima_user_DllExport std::array<char, 20>& message();

/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(
size_t current_alignment = 0);

/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(
const HelloWorld& data,
size_t current_alignment = 0);


/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& cdr) const;

/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr);



/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(
size_t current_alignment = 0);

/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();

/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(
eprosima::fastcdr::Cdr& cdr) const;

private:

uint32_t m_index;
std::array<char, 20> m_message;
uint32_t m_index{0};
std::array<char, 20> m_message{0};

};

#endif // _FAST_DDS_GENERATED_HELLOWORLD_H_



#endif // FASTCDR_VERSION_MAJOR > 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file HelloWorldCdrAux.hpp
* This source file contains some definitions of CDR related functions.
*
* This file was generated by the tool fastddsgen.
*/

#ifndef _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_
#define _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_

#include "HelloWorld.h"

constexpr uint32_t HelloWorld_max_cdr_typesize {28UL};
constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL};


namespace eprosima {
namespace fastcdr {

class Cdr;
class CdrSizeCalculator;



eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const HelloWorld& data);


} // namespace fastcdr
} // namespace eprosima

#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_

Loading

0 comments on commit 208dadc

Please sign in to comment.