Skip to content

Commit

Permalink
Documentation to serialize DynamicData to JSON (#844)
Browse files Browse the repository at this point in the history
* Documentation to serialize DynamicData to JSON

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Change section name and set JSON to not filled DynamicData

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Add Supported Types Serialization section and add more verbosity

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Add json_serialize API, references and change example

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Apply suggested changes

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Fix spelling errors

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Remove unnecessary idl

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Apply suggested changes

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Add bitset section

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Apply minor change

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

* Add missing blank space in file

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>

---------

Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>
  • Loading branch information
LuciaEchevarria99 authored Jul 11, 2024
1 parent 4fa7593 commit 2885461
Show file tree
Hide file tree
Showing 20 changed files with 417 additions and 0 deletions.
31 changes: 31 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 Down Expand Up @@ -1156,6 +1157,36 @@ 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_);

SampleInfo info;

while ((RETCODE_OK == reader->take_next_sample(&new_data, &info)))
{
std::stringstream output;
output << std::setw(4);

// Serialize DynamicData into JSON string format
json_serialize(new_data, DynamicDataJsonFormat::EPROSIMA, output);
std::cout << "Message received:\n" << output.str() << std::endl;
}
}

// DynamicType created in discovery callback
DynamicType::_ref_type dyn_type_;
//!--
};
//!--

void dds_discovery_examples()
{
using Locator_t = eprosima::fastdds::rtps::Locator_t;
Expand Down
23 changes: 23 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 Expand Up @@ -190,6 +197,22 @@ struct BitsetStruct
};
//!--

//!--IDL_BITSET_JSON
bitset MyBitSet
{
bitfield<3> a;
bitfield<1> b;
bitfield<4>;
bitfield<10> c;
bitfield<12, short> d;
};

struct BitsetStruct
{
MyBitSet my_bitset;
};
//!--

//!--IDL_CUSTOM_ANNOTATION
@annotation MyAnnotation
{
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
}
8 changes: 8 additions & 0 deletions code/json/Bitsets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"my_bitset": {
"a": 0,
"b": 0,
"c": 0,
"d": 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

0 comments on commit 2885461

Please sign in to comment.