Skip to content

Commit

Permalink
DynamicData to JSON serializer
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
  • Loading branch information
juanlofer-eprosima committed May 14, 2024
1 parent 87f579c commit adb273a
Show file tree
Hide file tree
Showing 3 changed files with 1,098 additions and 0 deletions.
66 changes: 66 additions & 0 deletions include/fastdds/dds/xtypes/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2024 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 utils.hpp
*/

#ifndef _FASTDDS_DDS_XTYPES_UTILS_HPP_
#define _FASTDDS_DDS_XTYPES_UTILS_HPP_

#include <iostream>
#include <string>

#include <fastdds/dds/core/ReturnCode.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicData.hpp>

namespace eprosima {
namespace fastdds {
namespace dds {

enum class DynamicDataJsonFormat
{
OMG,
EPROSIMA,
};

/*!
* Serializes a @ref DynamicData into a JSON object, which is then dumped into an @ref std::ostream.
* @param[in] data @ref DynamicData reference to be serialized.
* @param[in,out] output @ref std::ostream reference where the JSON object is dumped.
* @param[in] format @ref DynamicDataJsonFormat JSON serialization format.
* @retval RETCODE_OK when serialization fully succeeds, and inner (member serialization) failing code otherwise.
*/
ReturnCode_t json_serialize(
const traits<DynamicData>::ref_type& data,
std::ostream& output,
DynamicDataJsonFormat format) noexcept;

/*!
* Serializes a @ref DynamicData into a JSON object, which is then dumped into a @ref std::string.
* @param[in] data @ref DynamicData reference to be serialized.
* @param[in,out] output @ref std::string reference where the JSON object is dumped.
* @param[in] format @ref DynamicDataJsonFormat JSON serialization format.
* @retval RETCODE_OK when serialization fully succeeds, and inner (member serialization) failing code otherwise.
*/
ReturnCode_t json_serialize(
const traits<DynamicData>::ref_type& data,
std::string& output,
DynamicDataJsonFormat format) noexcept;

} // dds
} // fastdds
} // eprosima

#endif // _FASTDDS_DDS_XTYPES_UTILS_HPP_
1 change: 1 addition & 0 deletions src/cpp/fastdds/xtypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ target_sources(fastdds-xtypes-dynamic-types-impl INTERFACE
dynamic_types/TypeDescriptorImpl.hpp
dynamic_types/VerbatimTextDescriptorImpl.cpp
dynamic_types/VerbatimTextDescriptorImpl.hpp
utils.cpp
)

target_link_libraries(fastdds-xtypes-dynamic-types-impl INTERFACE fastdds-xtypes-dynamic-types-api)
Expand Down
Loading

0 comments on commit adb273a

Please sign in to comment.