Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20903] Documentation to serialize DynamicData to JSON #844

Merged
merged 11 commits into from
Jul 11, 2024
24 changes: 24 additions & 0 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilder.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/utils.hpp>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/WriteParams.hpp>
#include <fastdds/rtps/history/IPayloadPool.hpp>
Expand All @@ -45,6 +46,7 @@
#include <fastdds/rtps/transport/network/AllowedNetworkInterface.hpp>
#include <fastdds/rtps/transport/network/BlockedNetworkInterface.hpp>
#include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>
#include <fastdds/rtps/transport/NetworkBuffer.hpp>
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.hpp>
#include <fastdds/rtps/transport/TCPTransportDescriptor.hpp>
#include <fastdds/rtps/transport/TCPv4TransportDescriptor.hpp>
Expand Down Expand Up @@ -1156,6 +1158,28 @@ class RemoteDiscoveryDomainParticipantListener : public DomainParticipantListene
};
//!--

//!--REMOTE_TYPE_INTROSPECTION
class TypeIntrospectionSubscriber : public DomainParticipantListener
{
//!--DYNDATA_JSON_SERIALIZATION
void on_data_available(
DataReader* reader)
{
// Dynamic DataType
DynamicData::_ref_type new_data =
DynamicDataFactory::get_instance()->create_data(dyn_type_);

std::stringstream output;

// Serialize DynamicData into JSON string format
json_serialize(new_data, DynamicDataJsonFormat::EPROSIMA, output);
std::cout << "Message received:\n" << output.str() << std::endl;
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved
}
//!--
DynamicType::_ref_type dyn_type_;
};
//!--

void dds_discovery_examples()
{
using Locator_t = eprosima::fastdds::rtps::Locator_t;
Expand Down
7 changes: 7 additions & 0 deletions code/DynamicTypesIDLExamples.idl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ struct ArrayStruct
};
//!--

//!--IDL_ARRAYS_JSON
struct ArrayStruct
{
long long_array[2][3];
};
//!--

//!--IDL_MAPS
struct MapStruct
{
Expand Down
14 changes: 14 additions & 0 deletions code/json/Arrays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"long_array": [
[
0,
0,
0
],
[
0,
0,
0
]
]
}
7 changes: 7 additions & 0 deletions code/json/Bitmask_EPROSIMA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"my_bitmask": {
"active": [],
"binary": "00000000",
"value": 0
}
}
3 changes: 3 additions & 0 deletions code/json/Bitmask_OMG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"my_bitmask": 0
}
6 changes: 6 additions & 0 deletions code/json/Enum_EPROSIMA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"my_enum": {
"name": "A",
"value": 0
}
}
3 changes: 3 additions & 0 deletions code/json/Enum_OMG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"my_enum": "A"
}
4 changes: 4 additions & 0 deletions code/json/Maps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"short_long_map": null,
"string_alias_unbounded_map": null
}
17 changes: 17 additions & 0 deletions code/json/Primitives.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"my_bool": false,
"my_octet": 0,
"my_char": "\u0000",
"my_wchar": "\u0000",
"my_long": 0,
"my_ulong": 0,
"my_int8": 0,
"my_uint8": 0,
"my_short": 0,
"my_ushort": 0,
"my_longlong": 0,
"my_ulonglong": 0,
"my_float": 0.0,
"my_double": 0.0,
"my_longdouble": 0.0
}
4 changes: 4 additions & 0 deletions code/json/Sequences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bitmask_sequence": [],
"short_sequence": []
}
6 changes: 6 additions & 0 deletions code/json/Strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"my_string": "",
"my_wstring": "",
"my_bounded_string": "",
"my_bounded_wstring": ""
}
7 changes: 7 additions & 0 deletions code/json/Structs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"complex_member": {
"first": 0
},
"first": 0.0,
"second": 0
}
10 changes: 10 additions & 0 deletions code/json/Unions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"inner_union": {
"second": 0
},
"complex_union": {
"fourth": {
"second": 0
}
}
}
1 change: 1 addition & 0 deletions docs/03-exports/aliases-api.include
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@
.. |ITypeObjectRegistry-api| replace:: :cpp:class:`ITypeObjectRegistry <eprosima::fastdds::dds::xtypes::ITypeObjectRegistry>`
.. |ITypeObjectRegistry::get_type_object| replace:: :cpp:func:`ITypeObjectRegistry::get_type_object <eprosima::fastdds::dds::xtypes::ITypeObjectRegistry::get_type_object>`
.. |TypeObjectUtils-api| replace:: :cpp:class:`TypeObjectUtils <eprosima::fastdds::dds::xtypes::TypeObjectUtils>`
.. |XTypesUtils-json_serialize-api| replace:: :cpp:func:`json_serialize <eprosima::fastdds::dds::json_serialize>`
.. }}}

.. |DomainParticipant::set_listener-api| replace:: :cpp:func:`DomainParticipant::set_listener()<eprosima::fastdds::dds::DomainParticipant::set_listener>`
Expand Down
9 changes: 9 additions & 0 deletions docs/fastdds/api_reference/dds_pim/xtypes/utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _api_pim_xtypes_utils:

.. rst-class:: api-ref

Utils
-----

.. doxygenfunction:: eprosima::fastdds::dds::json_serialize
:project: FastDDS
1 change: 1 addition & 0 deletions docs/fastdds/api_reference/dds_pim/xtypes/xtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ XTypes
/fastdds/api_reference/dds_pim/xtypes/dynamic_types.rst
/fastdds/api_reference/dds_pim/xtypes/exception.rst
/fastdds/api_reference/dds_pim/xtypes/type_representation.rst
/fastdds/api_reference/dds_pim/xtypes/utils.rst
2 changes: 2 additions & 0 deletions docs/fastdds/api_reference/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ untaken
untyped
url
UserAllocatedSequence
Utils
utils
wakeup
wdata
WLPListener
Expand Down
Loading
Loading