diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index 4f3240f03..a017b3ca2 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -880,6 +880,28 @@ void dds_domain_examples() "fastdds.tcp_transport.non_blocking_send", "true"); //!-- + } + + { + // MAX_MESSAGE_SIZE_PROPERTY_PARTICIPANT + DomainParticipantQos pqos; + + // Set maximum number of bytes of the datagram to be sent + pqos.properties().properties().emplace_back( + "fastdds.max_message_size", + "1200"); + //!-- + } + + { + // MAX_MESSAGE_SIZE_PROPERTY_WRITER + DataWriterQos wqos; + + // Set maximum number of bytes of the datagram to be sent + wqos.properties().properties().emplace_back( + "fastdds.max_message_size", + "1200"); + //!-- } } @@ -4410,6 +4432,845 @@ void log_examples() } +<<<<<<< HEAD +======= +void dynamictypes_examples() +{ + { + //!--CPP_PRIMITIVES + // Define a struct type with various primitive members + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("PrimitivesStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define and add primitive members to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_bool"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_octet"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BYTE)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_char"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_wchar"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_long"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_ulong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_int8"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT8)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_uint8"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT8)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_short"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_ushort"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT16)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_longlong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_ulonglong"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT64)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_float"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT32)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_double"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT64)); + struct_builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->name("my_longdouble"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT128)); + struct_builder->add_member(member_descriptor); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for a member of type int32_t + int32_t in_value {2}; + int32_t out_value {0}; + data->set_int32_value(data->get_member_id_by_name("my_long"), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name("my_long")); + //!-- + } + { + //!--CPP_STRINGS + // Define a struct type to contain the strings + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("StringsStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define and add string members to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + + member_descriptor->name("my_string"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRING8); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + type_descriptor->bound().push_back(static_cast(LENGTH_UNLIMITED)); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build()); + */ + + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_wstring"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_wstring_type(static_cast(LENGTH_UNLIMITED))->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRING16); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + type_descriptor->bound().push_back(static_cast(LENGTH_UNLIMITED)); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build()); + */ + + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_bounded_string"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_string_type(41925)->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRING8); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + type_descriptor->bound().push_back(41925); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build()); + */ + + struct_builder->add_member(member_descriptor); + member_descriptor->name("my_bounded_wstring"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + create_wstring_type(20925)->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRING16); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + type_descriptor->bound().push_back(20925); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)->build()); + */ + + struct_builder->add_member(member_descriptor); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for a string member + std::string in_value {"helloworld"}; + std::string out_value; + data->set_string_value(data->get_member_id_by_name("my_string"), in_value); + data->get_string_value(out_value, data->get_member_id_by_name("my_string")); + //!-- + } + { + //!--CPP_ENUM + enum MyEnum : uint32_t + { + A, + B, + C + }; + + // Define a struct type to contain an enum + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("EnumStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define the enum type + TypeDescriptor::_ref_type enum_type_descriptor {traits::make_shared()}; + enum_type_descriptor->kind(TK_ENUM); + enum_type_descriptor->name("MyEnum"); + DynamicTypeBuilder::_ref_type enum_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(enum_type_descriptor)}; + // Add enum literals to the enum type + MemberDescriptor::_ref_type enum_member_descriptor {traits::make_shared()}; + enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + enum_member_descriptor->name("A"); + enum_builder->add_member(enum_member_descriptor); + enum_member_descriptor = traits::make_shared(); + enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + enum_member_descriptor->name("B"); + enum_builder->add_member(enum_member_descriptor); + enum_member_descriptor = traits::make_shared(); + enum_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + enum_member_descriptor->name("C"); + enum_builder->add_member(enum_member_descriptor); + // Build the enum type + DynamicType::_ref_type enum_type = enum_builder->build(); + + // Add an enum member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_enum"); + member_descriptor->type(enum_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for an enum member + MyEnum in_value {MyEnum::C}; + + /* Alternative + uint32_t in_value {2}; // Selecting MyEnum::C + */ + + uint32_t out_value {0}; + data->set_uint32_value(data->get_member_id_by_name("my_enum"), in_value); + data->get_uint32_value(out_value, data->get_member_id_by_name("my_enum")); + //!-- + } + { + //!--CPP_BITMASK + // Define a struct type to contain a bitmask + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("BitmaskStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define the bitmask type + DynamicTypeBuilder::_ref_type bitmask_builder {DynamicTypeBuilderFactory::get_instance()->create_bitmask_type(8)}; + + /* Alternative + TypeDescriptor::_ref_type bitmask_type_descriptor {traits::make_shared()}; + bitmask_type_descriptor->kind(TK_BITMASK); + bitmask_type_descriptor->name("MyBitMask"); + bitmask_type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type( + TK_BOOLEAN)); + bitmask_type_descriptor->bound().push_back(8); + DynamicTypeBuilder::_ref_type bitmask_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + bitmask_type_descriptor)}; + */ + + // Add bitfield members to the bitmask type + MemberDescriptor::_ref_type bitfield_member_descriptor {traits::make_shared()}; + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag0"); + bitfield_member_descriptor->id(0); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag1"); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag2"); + bitmask_builder->add_member(bitfield_member_descriptor); + bitfield_member_descriptor = traits::make_shared(); + bitfield_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + bitfield_member_descriptor->name("flag5"); + bitfield_member_descriptor->id(5); + bitmask_builder->add_member(bitfield_member_descriptor); + // Build the bitmask type + DynamicType::_ref_type bitmask_type = bitmask_builder->build(); + + // Add a bitmask member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_bitmask"); + member_descriptor->type(bitmask_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for bitmask member. + uint8_t in_value {3}; // Setting both "flag0" and "flag1" simultaneously. + uint8_t out_value {0}; + data->set_uint8_value(data->get_member_id_by_name("my_bitmask"), in_value); + data->get_uint8_value(out_value, data->get_member_id_by_name("my_bitmask")); + + // Set and retrieve specific bitflag + bool in_bitflag_value = true; + bool out_bitflag_value = false; + DynamicData::_ref_type bitmask_data = data->loan_value(data->get_member_id_by_name("my_bitmask")); + bitmask_data->set_boolean_value(bitmask_data->get_member_id_by_name("flag5"), in_bitflag_value); + bitmask_data->get_boolean_value(out_bitflag_value, bitmask_data->get_member_id_by_name("flag5")); + //!-- + } + { + // Type created as described in enumeration type section. + enum MyEnum : int32_t + { + A, + B, + C + }; + DynamicType::_ref_type enum_type; + + //!--CPP_TYPEDEF + // Define a struct type to contain the alias + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("AliasStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define an alias type for the enum + TypeDescriptor::_ref_type aliasenum_type_descriptor {traits::make_shared()}; + aliasenum_type_descriptor->kind(TK_ALIAS); + aliasenum_type_descriptor->name("MyAliasedEnum"); + aliasenum_type_descriptor->base_type(enum_type); + DynamicTypeBuilder::_ref_type aliasenum_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(aliasenum_type_descriptor)}; + // Build the alias type + DynamicType::_ref_type aliasenum_type = aliasenum_builder->build(); + + // Define an alias type for a bounded string + TypeDescriptor::_ref_type alias_bounded_string_type_descriptor {traits::make_shared()}; + alias_bounded_string_type_descriptor->kind(TK_ALIAS); + alias_bounded_string_type_descriptor->name("MyAliasedBoundedString"); + alias_bounded_string_type_descriptor->base_type(DynamicTypeBuilderFactory::get_instance()-> + create_string_type(100)->build()); + DynamicTypeBuilder::_ref_type alias_bounded_string_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(alias_bounded_string_type_descriptor)}; + // Build the alias type for the bounded string + DynamicType::_ref_type alias_bounded_string_type = alias_bounded_string_builder->build(); + + // Define a recursive alias + TypeDescriptor::_ref_type recursive_alias_type_descriptor {traits::make_shared()}; + recursive_alias_type_descriptor->kind(TK_ALIAS); + recursive_alias_type_descriptor->name("MyRecursiveAlias"); + recursive_alias_type_descriptor->base_type(aliasenum_type); + DynamicTypeBuilder::_ref_type recursive_alias_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(recursive_alias_type_descriptor)}; + // Build the recursive alias type + DynamicType::_ref_type recursive_alias_type = recursive_alias_builder->build(); + + // Add alias enum member to the structure + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_aliased_enum"); + member_descriptor->type(aliasenum_type); + struct_builder->add_member(member_descriptor); + // Add alias bounded string member to the structure + member_descriptor = traits::make_shared(); + member_descriptor->name("my_aliased_bounded_string"); + member_descriptor->type(alias_bounded_string_type); + struct_builder->add_member(member_descriptor); + // Add recursive alias member to the structure + member_descriptor = traits::make_shared(); + member_descriptor->name("my_recursive_alias"); + member_descriptor->type(recursive_alias_type); + struct_builder->add_member(member_descriptor); + + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the alias enum member + MyEnum in_value {MyEnum::C}; + int32_t out_value {0}; + data->set_int32_value(data->get_member_id_by_name("my_alias_enum"), in_value); + data->get_int32_value(out_value, data->get_member_id_by_name("my_alias_enum")); + //!-- + } + { + // Type created as described in enumeration type section. + DynamicType::_ref_type bitmask_type; + + //!--CPP_SEQUENCES + // Define a struct type to contain the sequence + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("SequenceStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + + // Define a member for the sequence + MemberDescriptor::_ref_type sequence_member_descriptor {traits::make_shared()}; + sequence_member_descriptor->name("bitmask_sequence"); + sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_sequence_type(bitmask_type, + static_cast(LENGTH_UNLIMITED))->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_SEQUENCE); + type_descriptor->element_type(bitmask_type); + type_descriptor->bound().push_back(static_cast(LENGTH_UNLIMITED)); + sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)->build()); + */ + + // Add the sequence member to the struct + struct_builder->add_member(sequence_member_descriptor); + + sequence_member_descriptor = traits::make_shared(); + sequence_member_descriptor->name("short_sequence"); + sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_sequence_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16), 5)->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_SEQUENCE); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + type_descriptor->bound().push_back(5); + sequence_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)->build()); + */ + + // Add the sequence member to the struct + struct_builder->add_member(sequence_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the sequence member + Int16Seq in_value = {1, 2}; + Int16Seq out_value; + data->set_int16_values(data->get_member_id_by_name("short_sequence"), in_value); + data->get_int16_values(out_value, data->get_member_id_by_name("short_sequence")); + + DynamicData::_ref_type sequence_data {data->loan_value(data->get_member_id_by_name("short_sequence"))}; + // Set the two latest possible values on the sequence + sequence_data->set_int16_values(3, in_value); + // Read every sequence value from index 1 to the end + sequence_data->get_int16_values(out_value, 1); + + int16_t in_simple_value = 8; + int16_t out_simple_value; + sequence_data->set_int16_value(2, in_simple_value); + sequence_data->get_int16_value(out_simple_value, 2); + + data->return_loaned_value(sequence_data); + //!-- + } + { + //!--CPP_ARRAYS + // Define a struct type to contain the array + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("ArrayStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define a member for the array + MemberDescriptor::_ref_type array_member_descriptor {traits::make_shared()}; + array_member_descriptor->name("long_array"); + array_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_array_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32), { 2, 3, 4 })->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_ARRAY); + type_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + type_descriptor->bound().push_back(2); + type_descriptor->bound().push_back(3); + type_descriptor->bound().push_back(4); + array_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)->build()); + */ + + // Add the array member to the struct + struct_builder->add_member(array_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Set and retrieve values for the array member + Int32Seq in_value = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 23, 24}; + Int32Seq out_value; + data->set_int32_values(data->get_member_id_by_name("long_array"), in_value); + data->get_int32_values(out_value, data->get_member_id_by_name("long_array")); + + DynamicData::_ref_type array_data {data->loan_value(data->get_member_id_by_name("long_array"))}; + // Set the two latest possible values on the array + Int32Seq small_in_value = {0, 1}; + array_data->set_int32_values(22, small_in_value); + // Read every array value from index 1 to the end + array_data->get_int32_values(out_value, 1); + + int32_t in_simple_value = 8; + int32_t out_simple_value; + array_data->set_int32_value(2, in_simple_value); + array_data->get_int32_value(out_simple_value, 2); + + data->return_loaned_value(array_data); + //!-- + } + { + // Type created as described in enumeration type section. + DynamicType::_ref_type alias_bounded_string_type; + + //!--CPP_MAPS + // Define a struct type to contain the map + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("MapStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Define a member for the map + MemberDescriptor::_ref_type map_member_descriptor {traits::make_shared()}; + map_member_descriptor->name("string_long_array_unbounded_map"); + map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_map_type( + DynamicTypeBuilderFactory::get_instance()->create_string_type(static_cast( + LENGTH_UNLIMITED))->build(), alias_bounded_string_type, static_cast( + LENGTH_UNLIMITED))->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_MAP); + type_descriptor->key_element_type(DynamicTypeBuilderFactory::get_instance()->create_string_type( + static_cast(LENGTH_UNLIMITED)->build()); + type_descriptor->element_type(alias_bounded_string_type); + type_descriptor->bound().push_back(static_cast(LENGTH_UNLIMITED)); + map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)->build()); + */ + + // Add the map member to the struct + struct_builder->add_member(map_member_descriptor); + + map_member_descriptor = traits::make_shared(); + map_member_descriptor->name("short_long_map"); + map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_map_type( + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16), + DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32), 2)->build()); + + /* Alternative + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_MAP); + type_descriptor->key_element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + type_descriptor->element_type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT32)); + type_descriptor->bound().push_back(2); + map_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_type( + type_descriptor)->build()); + */ + + struct_builder->add_member(map_member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + + // Get the data loan of the map member + DynamicData::_ref_type map_data = data->loan_value(data->get_member_id_by_name("short_long_map")); + + // Set and retrieve values for the map member + int32_t key {1}; + int32_t in_value {2}; + int32_t out_value; + map_data->set_int32_value(map_data->get_member_id_by_name(std::to_string(key)), in_value); + map_data->get_int32_value(out_value, map_data->get_member_id_by_name(std::to_string(key))); + + // Return de data loan of the map member + data->return_loaned_value(map_data); + //!-- + } + { + //!--CPP_STRUCT + // Create inner struct type + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(eprosima::fastdds::dds::TK_STRUCTURE); + type_descriptor->name("InnerStruct"); + DynamicTypeBuilder::_ref_type builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + // Add members to the inner struct type + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(eprosima::fastdds::dds::TK_INT32)); + member_descriptor->name("first"); + member_descriptor->id(16); + builder->add_member(member_descriptor); + // Build the inner struct type + DynamicType::_ref_type inner_struct_type {builder->build()}; + + // Create parent struct type + TypeDescriptor::_ref_type parentstruct_type_descriptor {traits::make_shared()}; + parentstruct_type_descriptor->kind(TK_STRUCTURE); + parentstruct_type_descriptor->name("ParentStruct"); + DynamicTypeBuilder::_ref_type parentstruct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(parentstruct_type_descriptor)}; + // Add members to the parent struct type + MemberDescriptor::_ref_type parentstruct_member {traits::make_shared()}; + parentstruct_member->name("first"); + parentstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_FLOAT32)); + parentstruct_builder->add_member(parentstruct_member); + parentstruct_member = traits::make_shared(); + parentstruct_member->name("second"); + parentstruct_member->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT64)); + parentstruct_builder->add_member(parentstruct_member); + // Build the parent struct type + DynamicType::_ref_type parentstruct_type = parentstruct_builder->build(); + + // Create complex struct type + TypeDescriptor::_ref_type complexstruct_type_descriptor {traits::make_shared()}; + complexstruct_type_descriptor->kind(TK_STRUCTURE); + complexstruct_type_descriptor->name("ComplexStruct"); + complexstruct_type_descriptor->base_type(parentstruct_type); + DynamicTypeBuilder::_ref_type complexstruct_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(complexstruct_type_descriptor)}; + // Add members to the complex struct type + MemberDescriptor::_ref_type complexstruct_member {traits::make_shared()}; + complexstruct_member->name("complex_member"); + complexstruct_member->type(inner_struct_type); + complexstruct_builder->add_member(complexstruct_member); + + // Build the complex struct type + DynamicType::_ref_type complexstruct_type = complexstruct_builder->build(); + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(complexstruct_type)}; + + // Set and retrieve values for member of type float + float in_value {3.14}; + float out_value {0.0}; + data->set_float32_value(data->get_member_id_by_name("first"), in_value); + data->get_float32_value(out_value, data->get_member_id_by_name("first")); + //!-- + } + + { + // Skipped this type creation: same as primitives struct created in previous section. + DynamicType::_ref_type struct_type; + + //!--CPP_UNION + // Define a struct type to contain the union + // Create the inner union + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_UNION); + type_descriptor->name("InnerUnion"); + type_descriptor->discriminator_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_INT16)); + DynamicTypeBuilder::_ref_type builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + // Add members to the inner union type + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->type(struct_type); + member_descriptor->name("first"); + member_descriptor->id(16); + member_descriptor->label({0}); + builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_INT64)); + member_descriptor->name("second"); + member_descriptor->label({1}); + member_descriptor->is_default_label(true); + builder->add_member(member_descriptor); + // Build the inner union type + DynamicType::_ref_type inner_union_type {builder->build()}; + + // Create a complex union type + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_UNION); + type_descriptor->name("ComplexUnion"); + type_descriptor->discriminator_type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_INT32)); + builder = DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor); + // Add members to the complex union type + member_descriptor = traits::make_shared(); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()-> + get_primitive_type(TK_INT32)); + member_descriptor->name("third"); + member_descriptor->label({0, 1}); + builder->add_member(member_descriptor); + member_descriptor = traits::make_shared(); + member_descriptor->type(inner_union_type); + member_descriptor->name("fourth"); + member_descriptor->is_default_label(true); + builder->add_member(member_descriptor); + // Build the complex union type + DynamicType::_ref_type union_type {builder->build()}; + + // Create dynamic data based on the union type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(union_type)}; + // Get the loan for the InnerUnion member + DynamicData::_ref_type union_data = data->loan_value(data->get_member_id_by_name("InnerUnion")); + + // Set and retrieve values for the long long member within InnerUnion member + int64_t in_value {2}; + int64_t out_value; + union_data->set_int64_value(union_data->get_member_id_by_name("second"), in_value); + union_data->get_int64_value(out_value, union_data->get_member_id_by_name("second")); + // Return de data loan of the member + data->return_loaned_value(union_data); + //!-- + } + { + //!--CPP_BITSET + // Define a struct type to contain the bitset + TypeDescriptor::_ref_type struct_type_descriptor {traits::make_shared()}; + struct_type_descriptor->kind(TK_STRUCTURE); + struct_type_descriptor->name("BitsetStruct"); + DynamicTypeBuilder::_ref_type struct_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + struct_type_descriptor)}; + + // Define type for parent bitset + TypeDescriptor::_ref_type bitset_type_descriptor {traits::make_shared()}; + bitset_type_descriptor->kind(TK_BITSET); + bitset_type_descriptor->name("ParentBitSet"); + bitset_type_descriptor->bound({3, 1, 10, 12}); + DynamicTypeBuilder::_ref_type bitset_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + bitset_type_descriptor)}; + // Add members to the bitset type + MemberDescriptor::_ref_type bitset_member_descriptor {traits::make_shared()}; + bitset_member_descriptor->name("a"); + bitset_member_descriptor->id(0); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("b"); + bitset_member_descriptor->id(3); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("c"); + bitset_member_descriptor->id(8); + bitset_builder->add_member(bitset_member_descriptor); + bitset_member_descriptor = traits::make_shared(); + bitset_member_descriptor->name("d"); + bitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + bitset_member_descriptor->id(18); + bitset_builder->add_member(bitset_member_descriptor); + // Build the bitset type + DynamicType::_ref_type parentbitset_type = bitset_builder->build(); + + // Create child bitset type + TypeDescriptor::_ref_type childbitset_type_descriptor {traits::make_shared()}; + childbitset_type_descriptor->kind(TK_BITSET); + childbitset_type_descriptor->name("ChildBitSet"); + childbitset_type_descriptor->base_type(parentbitset_type); + childbitset_type_descriptor->bound({1, 20}); + DynamicTypeBuilder::_ref_type childbitset_builder {DynamicTypeBuilderFactory::get_instance()->create_type( + childbitset_type_descriptor)}; + // Add members to the child bitset type + MemberDescriptor::_ref_type childbitset_member_descriptor {traits::make_shared()}; + childbitset_member_descriptor->name("e"); + childbitset_member_descriptor->id(30); + childbitset_builder->add_member(childbitset_member_descriptor); + childbitset_member_descriptor = traits::make_shared(); + childbitset_member_descriptor->name("d"); + childbitset_member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_UINT32)); + childbitset_member_descriptor->id(31); + childbitset_builder->add_member(childbitset_member_descriptor); + // Build the child bitset type + DynamicType::_ref_type bitset_type = childbitset_builder->build(); + + // Add the bitset member to the struct + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("my_bitset"); + member_descriptor->type(bitset_type); + struct_builder->add_member(member_descriptor); + // Build the struct type + DynamicType::_ref_type struct_type {struct_builder->build()}; + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + // Get the loan for the bitset member + DynamicData::_ref_type bitset_data = data->loan_value(data->get_member_id_by_name("my_bitset")); + + // Set and retrieve bitfield values + int16_t in_value {2}; + int16_t out_value; + bitset_data->set_int16_value(bitset_data->get_member_id_by_name("d"), in_value); + bitset_data->get_int16_value(out_value, bitset_data->get_member_id_by_name("d")); + // Return de data loan of the member + data->return_loaned_value(bitset_data); + //!-- + } + { + //!--CPP_CUSTOM_ANNOTATION + // Create the structure to annotate + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name("AnnotatedStruct"); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(type_descriptor)}; + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name("string_var"); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(static_cast( + LENGTH_UNLIMITED))->build()); + type_builder->add_member(member_descriptor); + + // Create the annotation type + AnnotationDescriptor::_ref_type annotation_descriptor {traits::make_shared()}; + TypeDescriptor::_ref_type annotation_type {traits::make_shared()}; + annotation_type->kind(TK_ANNOTATION); + annotation_type->name("MyAnnotation"); + DynamicTypeBuilder::_ref_type annotation_builder {DynamicTypeBuilderFactory::get_instance()-> + create_type(annotation_type)}; + + // Add members to the annotation type + MemberDescriptor::_ref_type annotation_parameter {traits::make_shared()}; + annotation_parameter->name("length"); + annotation_parameter->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + annotation_builder->add_member(annotation_parameter); + // Set the annotation type using the annotation descriptor + annotation_descriptor->type(annotation_builder->build()); + // Set the value of the annotation + annotation_descriptor->set_value("length", std::to_string(5)); + // Apply the annotation to the structure + type_builder->apply_annotation(annotation_descriptor); + + // Reuse annotation descriptor to annotate struct member + annotation_descriptor = traits::make_shared(); + annotation_descriptor->type(annotation_builder->build()); + annotation_descriptor->set_value("length", std::to_string(10)); + + DynamicTypeMember::_ref_type member; + type_builder->get_member_by_name(member, "string_var"); + type_builder->apply_annotation_to_member(member->get_id(), annotation_descriptor); + //!-- + } + { + // Complex struct type defined previously + DynamicType::_ref_type complexstruct_type; + //!--CPP_COMPLEX_DATA + // Create dynamic data based on the struct type + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(complexstruct_type)}; + + // Get/Set complex API (copy) + DynamicData::_ref_type complex_data; + data->get_complex_value(complex_data, data->get_member_id_by_name("complex_member")); + // Set data + int32_t in_value {10}; + complex_data->set_int32_value(complex_data->get_member_id_by_name("first"), in_value); + data->set_complex_value(data->get_member_id_by_name("complex_member"), complex_data); + + // Loan API + DynamicData::_ref_type loan_data = data->loan_value(data->get_member_id_by_name("complex_member")); + loan_data->set_int32_value(loan_data->get_member_id_by_name("first"), in_value); + int32_t out_value; + loan_data->get_int32_value(out_value, loan_data->get_member_id_by_name("first")); + data->return_loaned_value(loan_data); + //!-- + } +} + +>>>>>>> 91d96b8 (New `max_message_size` property to limit output datagrams size (#770)) void xml_profiles_examples() { { diff --git a/code/XMLTester.xml b/code/XMLTester.xml index c6281d54f..f714885fb 100644 --- a/code/XMLTester.xml +++ b/code/XMLTester.xml @@ -2790,6 +2790,42 @@ --> <--> +MAX_MESSAGE_SIZE_PROPERTY_PARTICIPANT<--> + + + + + + + + fastdds.max_message_size + 1200 + + + + + +<--> + +MAX_MESSAGE_SIZE_PROPERTY_WRITER<--> + + + + + + + fastdds.max_message_size + 1200 + + + + +<--> + FASTDDS_STATISTICS_MODULE<--> diff --git a/docs/fastdds/property_policies/non_consolidated_qos.rst b/docs/fastdds/property_policies/non_consolidated_qos.rst index 9858014d1..c9a84e85a 100644 --- a/docs/fastdds/property_policies/non_consolidated_qos.rst +++ b/docs/fastdds/property_policies/non_consolidated_qos.rst @@ -395,3 +395,82 @@ packet. :language: xml :start-after: XML-TCP-NON-BLOCKING-SEND :end-before: <--> + +.. _property_max_message_size: + +Maximum Message Size +^^^^^^^^^^^^^^^^^^^^ + +One common requirement is the differentiation between the maximum size of received and sent datagrams. +This capability is especially important in scenarios where a system might need to handle large incoming +data sizes but should restrict the size of the data it sends to prevent overwhelming network resources +or complying with network traffic policies. +The primary attribute for controlling datagram size is `maxMessageSize`, which sets the upper limit +for both the size of datagrams that can be received and those that can be sent. +Property ``fastdds.max_message_size`` allows restricting the size of outgoing datagrams without +changing the size of incoming ones. +This property allows for the specific configuration of the maximum number of bytes for datagrams that +are sent. +By configuring this property to a value lower than the smallest `maxMessageSize` across all transports, +applications can achieve a lower sending limit while maintaining the ability to receive larger datagrams. + +.. list-table:: + :header-rows: 1 + :align: left + + * - PropertyPolicyQos name + - PropertyPolicyQos value + - Default value + * - ``"fastdds.max_message_size"`` + - ``uint32_t`` + - ``"4294967295"`` + +.. note:: + An invalid value of ``fastdds.max_message_size`` would log an error, + and the default value will be used. + +.. _setting_max_message_size_participant: + +Setting ``fastdds.max_message_size`` At Participant Level +""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +.. tabs:: + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: // MAX_MESSAGE_SIZE_PROPERTY_PARTICIPANT + :end-before: //!-- + :dedent: 6 + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: MAX_MESSAGE_SIZE_PROPERTY_PARTICIPANT<--> + :end-before: <--> + :lines: 2,4-16 + +.. _setting_max_message_size_writer: + +Setting ``fastdds.max_message_size`` At Writer Level +"""""""""""""""""""""""""""""""""""""""""""""""""""" + +.. tabs:: + + .. tab:: C++ + + .. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: // MAX_MESSAGE_SIZE_PROPERTY_WRITER + :end-before: //!-- + :dedent: 6 + + .. tab:: XML + + .. literalinclude:: /../code/XMLTester.xml + :language: xml + :start-after: MAX_MESSAGE_SIZE_PROPERTY_WRITER<--> + :end-before: <--> + :lines: 2,4-14