Skip to content

Commit

Permalink
add blob, blob-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Nov 26, 2023
1 parent 2b5fecb commit d7afc32
Show file tree
Hide file tree
Showing 9 changed files with 848 additions and 1 deletion.
86 changes: 86 additions & 0 deletions third-party/realdds/include/realdds/topics/blob-msg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
#pragma once

#include "blob/blob.h"
#include <realdds/dds-defines.h>

#include <string>
#include <memory>
#include <vector>


namespace eprosima {
namespace fastdds {
namespace dds {
struct SampleInfo;
}
} // namespace fastdds
} // namespace eprosima


namespace udds {
class blobPubSubType;
} // namespace raw


namespace realdds {


class dds_participant;
class dds_topic;
class dds_topic_reader;
class dds_topic_writer;


namespace topics {


class blob_msg : public udds::blob
{
public:
using type = udds::blobPubSubType;

blob_msg() = default;
blob_msg( std::vector< uint8_t > && data_ ) { data( std::move( data_ ) ); }

bool is_valid() const { return ! data().empty(); }
void invalidate() { data().clear(); }

static std::shared_ptr< dds_topic > create_topic( std::shared_ptr< dds_participant > const & participant,
char const * topic_name );
static std::shared_ptr< dds_topic > create_topic( std::shared_ptr< dds_participant > const & participant,
std::string const & topic_name )
{
return create_topic( participant, topic_name.c_str() );
}

// This helper method will take the next sample from a reader.
//
// Returns true if successful. Make sure you still check is_valid() in case the sample info isn't!
// Returns false if no more data is available.
// Will throw if an unexpected error occurs.
//
static bool take_next( dds_topic_reader &,
blob_msg * output,
eprosima::fastdds::dds::SampleInfo * optional_info = nullptr );

// Returns some unique (to the writer) identifier for the sample that was sent, or 0 if unsuccessful
dds_sequence_number write_to( dds_topic_writer & ) const;

// Cast the raw data to the desired type
template< typename T >
T const * custom_data() const
{
return data().size() > 0 ? reinterpret_cast< T const * >( data().data() ) : nullptr;
}
template< typename T >
T * custom_data()
{
return data().size() > 0 ? reinterpret_cast< T * >( data().data() ) : nullptr;
}
};


} // namespace topics
} // namespace realdds
205 changes: 205 additions & 0 deletions third-party/realdds/include/realdds/topics/blob/blob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

/*!
* @file blob.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/

#ifndef _FAST_DDS_GENERATED_UDDS_BLOB_H_
#define _FAST_DDS_GENERATED_UDDS_BLOB_H_


//#include <fastrtps/utils/fixed_size_string.hpp>

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

#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif // EPROSIMA_USER_DLL_EXPORT
#else
#define eProsima_user_DllExport
#endif // _WIN32

#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(blob_SOURCE)
#define blob_DllAPI __declspec( dllexport )
#else
#define blob_DllAPI __declspec( dllimport )
#endif // blob_SOURCE
#else
#define blob_DllAPI
#endif // EPROSIMA_USER_DLL_EXPORT
#else
#define blob_DllAPI
#endif // _WIN32

namespace eprosima {
namespace fastcdr {
class Cdr;
} // namespace fastcdr
} // namespace eprosima


namespace udds {
/*!
* @brief This class represents the structure blob defined by the user in the IDL file.
* @ingroup BLOB
*/
class blob
{
public:

/*!
* @brief Default constructor.
*/
eProsima_user_DllExport blob();

/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~blob();

/*!
* @brief Copy constructor.
* @param x Reference to the object udds::blob that will be copied.
*/
eProsima_user_DllExport blob(
const blob& x);

/*!
* @brief Move constructor.
* @param x Reference to the object udds::blob that will be copied.
*/
eProsima_user_DllExport blob(
blob&& x) noexcept;

/*!
* @brief Copy assignment.
* @param x Reference to the object udds::blob that will be copied.
*/
eProsima_user_DllExport blob& operator =(
const blob& x);

/*!
* @brief Move assignment.
* @param x Reference to the object udds::blob that will be copied.
*/
eProsima_user_DllExport blob& operator =(
blob&& x) noexcept;

/*!
* @brief Comparison operator.
* @param x udds::blob object to compare.
*/
eProsima_user_DllExport bool operator ==(
const blob& x) const;

/*!
* @brief Comparison operator.
* @param x udds::blob object to compare.
*/
eProsima_user_DllExport bool operator !=(
const blob& x) const;

/*!
* @brief This function copies the value in member data
* @param _data New value to be copied in member data
*/
eProsima_user_DllExport void data(
const std::vector<uint8_t>& _data);

/*!
* @brief This function moves the value in member data
* @param _data New value to be moved in member data
*/
eProsima_user_DllExport void data(
std::vector<uint8_t>&& _data);

/*!
* @brief This function returns a constant reference to member data
* @return Constant reference to member data
*/
eProsima_user_DllExport const std::vector<uint8_t>& data() const;

/*!
* @brief This function returns a reference to member data
* @return Reference to member data
*/
eProsima_user_DllExport std::vector<uint8_t>& data();

/*!
* @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 udds::blob& 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:

std::vector<uint8_t> m_data;
};
} // namespace udds

#endif // _FAST_DDS_GENERATED_UDDS_BLOB_H_
10 changes: 10 additions & 0 deletions third-party/realdds/include/realdds/topics/blob/blob.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

module udds
{
struct blob
{
sequence<octet> data;
};
};
93 changes: 93 additions & 0 deletions third-party/realdds/include/realdds/topics/blob/blobPubSubTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

/*!
* @file blobPubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/


#ifndef _FAST_DDS_GENERATED_UDDS_BLOB_PUBSUBTYPES_H_
#define _FAST_DDS_GENERATED_UDDS_BLOB_PUBSUBTYPES_H_

#include <fastdds/dds/topic/TopicDataType.hpp>
#include <fastrtps/utils/md5.h>

#include "blob.h"

#if !defined(GEN_API_VER) || (GEN_API_VER != 1)
#error \
Generated blob is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen.
#endif // GEN_API_VER

namespace udds
{
/*!
* @brief This class represents the TopicDataType of the type blob defined by the user in the IDL file.
* @ingroup BLOB
*/
class blobPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:

typedef blob type;

eProsima_user_DllExport blobPubSubType();

eProsima_user_DllExport virtual ~blobPubSubType() override;

eProsima_user_DllExport virtual bool serialize(
void* data,
eprosima::fastrtps::rtps::SerializedPayload_t* payload) override;

eProsima_user_DllExport virtual bool deserialize(
eprosima::fastrtps::rtps::SerializedPayload_t* payload,
void* data) override;

eProsima_user_DllExport virtual std::function<uint32_t()> getSerializedSizeProvider(
void* data) override;

eProsima_user_DllExport virtual bool getKey(
void* data,
eprosima::fastrtps::rtps::InstanceHandle_t* ihandle,
bool force_md5 = false) override;

eProsima_user_DllExport virtual void* createData() override;

eProsima_user_DllExport virtual void deleteData(
void* data) override;

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain() const override
{
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN

#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
(void)memory;
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE

MD5 m_md5;
unsigned char* m_keyBuffer;
};
}

#endif // _FAST_DDS_GENERATED_UDDS_BLOB_PUBSUBTYPES_H_
Loading

0 comments on commit d7afc32

Please sign in to comment.