Skip to content

Commit b4d628c

Browse files
Add support for ROS 2 types
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent 44310c4 commit b4d628c

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
@@ -107,6 +107,7 @@ set(${PROJECT_NAME}_source_files
107107
fastdds/xtypes/exception/Exception.cpp
108108
fastdds/xtypes/serializers/idl/dynamic_type_idl.cpp
109109
fastdds/xtypes/serializers/json/dynamic_data_json.cpp
110+
fastdds/xtypes/serializers/json/json_dynamic_data.cpp
110111
fastdds/xtypes/type_representation/dds_xtypes_typeobjectPubSubTypes.cxx
111112
fastdds/xtypes/type_representation/TypeObjectRegistry.cpp
112113
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
@@ -501,7 +501,7 @@ ReturnCode_t json_serialize_member(
501501
}
502502
default:
503503
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
504-
"Error encountered while serializing map member to JSON: unexpected kind " << member_kind <<
504+
"Error encountered while serializing member to JSON: unexpected kind " << member_kind <<
505505
" found.");
506506
return RETCODE_BAD_PARAMETER;
507507
}
@@ -746,7 +746,7 @@ ReturnCode_t json_serialize_basic_member(
746746
// Insert UTF-8 converted value
747747
std::wstring aux_wstring_value({value});
748748
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
749-
std::string utf8_value = converter.to_bytes(aux_wstring_value);
749+
std::string utf8_value = converter.to_bytes(aux_wstring_value); // TODO: handle exception
750750
json_insert(member_name, utf8_value, output);
751751
}
752752
else
@@ -777,7 +777,7 @@ ReturnCode_t json_serialize_basic_member(
777777
{
778778
// Insert UTF-8 converted value
779779
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
780-
std::string utf8_value = converter.to_bytes(value);
780+
std::string utf8_value = converter.to_bytes(value); // TODO: handle exception
781781
json_insert(member_name, utf8_value, output);
782782
}
783783
else

0 commit comments

Comments
 (0)