Skip to content

Commit 1952842

Browse files
juanlofer-eprosimaEugenioCollado
authored andcommitted
Add support for ROS 2 types
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent 654ae69 commit 1952842

6 files changed

Lines changed: 698 additions & 3 deletions

File tree

include/fastdds/dds/xtypes/utils.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ FASTDDS_EXPORTED_API ReturnCode_t json_serialize(
6060
DynamicDataJsonFormat format,
6161
std::ostream& output) noexcept;
6262

63+
/*!
64+
* Deserializes a JSON object string into a @ref DynamicData.
65+
* @param[in] input JSON object string to be deserialized.
66+
* @param[in] dynamic_type @ref DynamicType corresponding to the @ref DynamicData where the JSON string is deserialized.
67+
* @param[in] format @ref DynamicDataJsonFormat JSON serialization format.
68+
* @param[in,out] data @ref DynamicData reference where the JSON string is deserialized. Must be null.
69+
* @retval RETCODE_OK when deserialization fully succeeds, RETCODE_BAD_PARAMETER when parsing fails or preconditions are not met, and inner (member deserialization) failing code otherwise.
70+
*/
71+
FASTDDS_EXPORTED_API ReturnCode_t json_deserialize(
72+
const std::string& input,
73+
const DynamicType::_ref_type& dynamic_type,
74+
DynamicDataJsonFormat format,
75+
DynamicData::_ref_type& data) noexcept;
76+
6377
} // dds
6478
} // fastdds
6579
} // eprosima

src/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ set(${PROJECT_NAME}_source_files
111111
fastdds/xtypes/exception/Exception.cpp
112112
fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp
113113
fastdds/xtypes/serializers/json/dynamic_data_json.cpp
114+
fastdds/xtypes/serializers/json/json_dynamic_data.cpp
114115
fastdds/xtypes/type_representation/dds_xtypes_typeobjectPubSubTypes.cxx
115116
fastdds/xtypes/type_representation/TypeObjectRegistry.cpp
116117
fastdds/xtypes/type_representation/TypeObjectUtils.cpp

src/cpp/fastdds/xtypes/serializers/json/dynamic_data_json.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ ReturnCode_t json_serialize_member(
503503
}
504504
default:
505505
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
506-
"Error encountered while serializing map member to JSON: unexpected kind " << member_kind <<
506+
"Error encountered while serializing member to JSON: unexpected kind " << member_kind <<
507507
" found.");
508508
return RETCODE_BAD_PARAMETER;
509509
}
@@ -758,7 +758,7 @@ ReturnCode_t json_serialize_basic_member(
758758
#else
759759
std::wstring aux_wstring_value({value});
760760
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
761-
std::string utf8_value = converter.to_bytes(aux_wstring_value);
761+
std::string utf8_value = converter.to_bytes(aux_wstring_value); // TODO: handle exception
762762

763763
#endif // defined(MINGW_COMPILER)
764764
json_insert(member_name, utf8_value, output);
@@ -800,7 +800,7 @@ ReturnCode_t json_serialize_basic_member(
800800
}
801801
#else
802802
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
803-
std::string utf8_value = converter.to_bytes(value);
803+
std::string utf8_value = converter.to_bytes(value); // TODO: handle exception
804804
#endif // defined(MINGW_COMPILER)
805805
json_insert(member_name, utf8_value, output);
806806
}

0 commit comments

Comments
 (0)