Skip to content

Commit 51a753c

Browse files
MiguelCompanymergify[bot]
authored andcommitted
Add support for bounded strings (#209)
* Refs #22835. Add bounded strings to test_complete.idl Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Add bounded strings to test_datareader.py Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Regenerate test types. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Remove optional fixed string. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Add SWIG interface for fixed_size_string. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Added fixed_string_field to test_modules.idl Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Fix issue. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Alternative solution. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Test both approaches. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Regenerate code with Fast DDS Gen. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> Signed-off-by: Miguel Company <[email protected]> (cherry picked from commit 5d53672)
1 parent 5ff8b4b commit 51a753c

16 files changed

+1709
-978
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
%{
16+
#include "fastcdr/cdr/fixed_size_string.hpp"
17+
%}
18+
19+
// Ignore method that causes warnings on SWIG
20+
%ignore eprosima::fastcdr::fixed_string::operator const char*() const;
21+
22+
%include "fastcdr/cdr/fixed_size_string.hpp"

fastdds_python/src/swig/fastdds.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ namespace xtypes {
136136
#ifndef FASTDDS_DOCS_BUILD
137137
%include <fastcdr/config.h>
138138
%include "fastcdr/xcdr/optional.i"
139+
%include "fastcdr/cdr/fixed_size_string.i"
139140
#endif
140141

141142
%include "fastdds/LibrarySettings.i"

fastdds_python/test/api/test_datareader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def fill_keyed_complete_test_type(data):
165165
data.double_field(1202.5)
166166
data.bool_field(True)
167167
data.string_field("Test string")
168+
fixed_string = pytest.dds_type.fixed_string_16("Fixed string")
169+
data.fixed_string_field(fixed_string)
168170
data.enum_field(pytest.dds_type.Color_MAGENTA)
169171
data.enum2_field(pytest.dds_type.Material_METAL)
170172
data.struct_field().char_field('\x01')
@@ -179,6 +181,7 @@ def fill_keyed_complete_test_type(data):
179181
data.struct_field().double_field(1202.5)
180182
data.struct_field().bool_field(False)
181183
data.struct_field().string_field("Test string")
184+
data.struct_field().fixed_string_field("Fixed string")
182185
data.struct_field().enum_field(pytest.dds_type.Color_MAGENTA)
183186
data.struct_field().enum2_field(pytest.dds_type.Material_METAL)
184187
data.char_opt_field().set_value('\x01')
@@ -207,6 +210,7 @@ def fill_keyed_complete_test_type(data):
207210
struct_field.double_field(1202.5)
208211
struct_field.bool_field(True)
209212
struct_field.string_field("Test string")
213+
struct_field.fixed_string_field("Fixed string")
210214
struct_field.enum_field(pytest.dds_type.Color_MAGENTA)
211215
struct_field.enum2_field(pytest.dds_type.Material_METAL)
212216
data.struct_opt_field().set_value(struct_field)
@@ -273,6 +277,7 @@ def check_keyed_complete_test_type(data):
273277
assert(data.double_field() == 1202.5)
274278
assert(data.bool_field() == True)
275279
assert(data.string_field() == "Test string")
280+
assert(data.fixed_string_field() == "Fixed string")
276281
assert(data.enum_field() == pytest.dds_type.Color_MAGENTA)
277282
assert(data.enum2_field() == pytest.dds_type.Material_METAL)
278283
assert(data.struct_field().char_field() == '\x01')
@@ -287,6 +292,7 @@ def check_keyed_complete_test_type(data):
287292
assert(data.struct_field().double_field() == 1202.5)
288293
assert(data.struct_field().bool_field() == False)
289294
assert(data.struct_field().string_field() == "Test string")
295+
assert(data.struct_field().fixed_string_field() == "Fixed string")
290296
assert(data.struct_field().enum_field() == pytest.dds_type.Color_MAGENTA)
291297
assert(data.struct_field().enum2_field() == pytest.dds_type.Material_METAL)
292298
assert(data.char_opt_field().has_value())
@@ -329,6 +335,7 @@ def check_keyed_complete_test_type(data):
329335
assert(data.struct_opt_field().double_field() == 1202.5)
330336
assert(data.struct_opt_field().bool_field() == True)
331337
assert(data.struct_opt_field().string_field() == "Test string")
338+
assert(data.struct_opt_field().fixed_string_field() == "Fixed string")
332339
assert(data.struct_opt_field().enum_field() == pytest.dds_type.Color_MAGENTA)
333340
assert(data.struct_opt_field().enum2_field() == pytest.dds_type.Material_METAL)
334341
assert(data.array_char_field()[0] == '\x01')

fastdds_python/test/types/test_complete.hpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class StructType
133133

134134
m_string_field = x.m_string_field;
135135

136+
m_fixed_string_field = x.m_fixed_string_field;
137+
136138
m_enum_field = x.m_enum_field;
137139

138140
m_enum2_field = x.m_enum2_field;
@@ -160,6 +162,7 @@ class StructType
160162
m_double_field = x.m_double_field;
161163
m_bool_field = x.m_bool_field;
162164
m_string_field = std::move(x.m_string_field);
165+
m_fixed_string_field = std::move(x.m_fixed_string_field);
163166
m_enum_field = x.m_enum_field;
164167
m_enum2_field = x.m_enum2_field;
165168
m_included_module_struct = std::move(x.m_included_module_struct);
@@ -197,6 +200,8 @@ class StructType
197200

198201
m_string_field = x.m_string_field;
199202

203+
m_fixed_string_field = x.m_fixed_string_field;
204+
200205
m_enum_field = x.m_enum_field;
201206

202207
m_enum2_field = x.m_enum2_field;
@@ -226,6 +231,7 @@ class StructType
226231
m_double_field = x.m_double_field;
227232
m_bool_field = x.m_bool_field;
228233
m_string_field = std::move(x.m_string_field);
234+
m_fixed_string_field = std::move(x.m_fixed_string_field);
229235
m_enum_field = x.m_enum_field;
230236
m_enum2_field = x.m_enum2_field;
231237
m_included_module_struct = std::move(x.m_included_module_struct);
@@ -251,6 +257,7 @@ class StructType
251257
m_double_field == x.m_double_field &&
252258
m_bool_field == x.m_bool_field &&
253259
m_string_field == x.m_string_field &&
260+
m_fixed_string_field == x.m_fixed_string_field &&
254261
m_enum_field == x.m_enum_field &&
255262
m_enum2_field == x.m_enum2_field &&
256263
m_included_module_struct == x.m_included_module_struct);
@@ -624,6 +631,45 @@ class StructType
624631
}
625632

626633

634+
/*!
635+
* @brief This function copies the value in member fixed_string_field
636+
* @param _fixed_string_field New value to be copied in member fixed_string_field
637+
*/
638+
eProsima_user_DllExport void fixed_string_field(
639+
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
640+
{
641+
m_fixed_string_field = _fixed_string_field;
642+
}
643+
644+
/*!
645+
* @brief This function moves the value in member fixed_string_field
646+
* @param _fixed_string_field New value to be moved in member fixed_string_field
647+
*/
648+
eProsima_user_DllExport void fixed_string_field(
649+
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
650+
{
651+
m_fixed_string_field = std::move(_fixed_string_field);
652+
}
653+
654+
/*!
655+
* @brief This function returns a constant reference to member fixed_string_field
656+
* @return Constant reference to member fixed_string_field
657+
*/
658+
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
659+
{
660+
return m_fixed_string_field;
661+
}
662+
663+
/*!
664+
* @brief This function returns a reference to member fixed_string_field
665+
* @return Reference to member fixed_string_field
666+
*/
667+
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
668+
{
669+
return m_fixed_string_field;
670+
}
671+
672+
627673
/*!
628674
* @brief This function sets a value in member enum_field
629675
* @param _enum_field New value for member enum_field
@@ -736,6 +782,7 @@ class StructType
736782
double m_double_field{0.0};
737783
bool m_bool_field{false};
738784
std::string m_string_field;
785+
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
739786
Color m_enum_field{Color::RED};
740787
Material m_enum2_field{Material::WOOD};
741788
eprosima::test2::StructType2 m_included_module_struct;
@@ -796,6 +843,8 @@ class CompleteTestType
796843

797844
m_string_field = x.m_string_field;
798845

846+
m_fixed_string_field = x.m_fixed_string_field;
847+
799848
m_enum_field = x.m_enum_field;
800849

801850
m_enum2_field = x.m_enum2_field;
@@ -937,6 +986,7 @@ class CompleteTestType
937986
m_double_field = x.m_double_field;
938987
m_bool_field = x.m_bool_field;
939988
m_string_field = std::move(x.m_string_field);
989+
m_fixed_string_field = std::move(x.m_fixed_string_field);
940990
m_enum_field = x.m_enum_field;
941991
m_enum2_field = x.m_enum2_field;
942992
m_struct_field = std::move(x.m_struct_field);
@@ -1031,6 +1081,8 @@ class CompleteTestType
10311081

10321082
m_string_field = x.m_string_field;
10331083

1084+
m_fixed_string_field = x.m_fixed_string_field;
1085+
10341086
m_enum_field = x.m_enum_field;
10351087

10361088
m_enum2_field = x.m_enum2_field;
@@ -1174,6 +1226,7 @@ class CompleteTestType
11741226
m_double_field = x.m_double_field;
11751227
m_bool_field = x.m_bool_field;
11761228
m_string_field = std::move(x.m_string_field);
1229+
m_fixed_string_field = std::move(x.m_fixed_string_field);
11771230
m_enum_field = x.m_enum_field;
11781231
m_enum2_field = x.m_enum2_field;
11791232
m_struct_field = std::move(x.m_struct_field);
@@ -1256,6 +1309,7 @@ class CompleteTestType
12561309
m_double_field == x.m_double_field &&
12571310
m_bool_field == x.m_bool_field &&
12581311
m_string_field == x.m_string_field &&
1312+
m_fixed_string_field == x.m_fixed_string_field &&
12591313
m_enum_field == x.m_enum_field &&
12601314
m_enum2_field == x.m_enum2_field &&
12611315
m_struct_field == x.m_struct_field &&
@@ -1686,6 +1740,45 @@ class CompleteTestType
16861740
}
16871741

16881742

1743+
/*!
1744+
* @brief This function copies the value in member fixed_string_field
1745+
* @param _fixed_string_field New value to be copied in member fixed_string_field
1746+
*/
1747+
eProsima_user_DllExport void fixed_string_field(
1748+
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
1749+
{
1750+
m_fixed_string_field = _fixed_string_field;
1751+
}
1752+
1753+
/*!
1754+
* @brief This function moves the value in member fixed_string_field
1755+
* @param _fixed_string_field New value to be moved in member fixed_string_field
1756+
*/
1757+
eProsima_user_DllExport void fixed_string_field(
1758+
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
1759+
{
1760+
m_fixed_string_field = std::move(_fixed_string_field);
1761+
}
1762+
1763+
/*!
1764+
* @brief This function returns a constant reference to member fixed_string_field
1765+
* @return Constant reference to member fixed_string_field
1766+
*/
1767+
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
1768+
{
1769+
return m_fixed_string_field;
1770+
}
1771+
1772+
/*!
1773+
* @brief This function returns a reference to member fixed_string_field
1774+
* @return Reference to member fixed_string_field
1775+
*/
1776+
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
1777+
{
1778+
return m_fixed_string_field;
1779+
}
1780+
1781+
16891782
/*!
16901783
* @brief This function sets a value in member enum_field
16911784
* @param _enum_field New value for member enum_field
@@ -4021,6 +4114,7 @@ class CompleteTestType
40214114
double m_double_field{0.0};
40224115
bool m_bool_field{false};
40234116
std::string m_string_field;
4117+
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
40244118
Color m_enum_field{Color::RED};
40254119
Material m_enum2_field{Material::WOOD};
40264120
StructType m_struct_field;
@@ -4138,6 +4232,8 @@ class KeyedCompleteTestType
41384232

41394233
m_string_field = x.m_string_field;
41404234

4235+
m_fixed_string_field = x.m_fixed_string_field;
4236+
41414237
m_enum_field = x.m_enum_field;
41424238

41434239
m_enum2_field = x.m_enum2_field;
@@ -4280,6 +4376,7 @@ class KeyedCompleteTestType
42804376
m_double_field = x.m_double_field;
42814377
m_bool_field = x.m_bool_field;
42824378
m_string_field = std::move(x.m_string_field);
4379+
m_fixed_string_field = std::move(x.m_fixed_string_field);
42834380
m_enum_field = x.m_enum_field;
42844381
m_enum2_field = x.m_enum2_field;
42854382
m_struct_field = std::move(x.m_struct_field);
@@ -4376,6 +4473,8 @@ class KeyedCompleteTestType
43764473

43774474
m_string_field = x.m_string_field;
43784475

4476+
m_fixed_string_field = x.m_fixed_string_field;
4477+
43794478
m_enum_field = x.m_enum_field;
43804479

43814480
m_enum2_field = x.m_enum2_field;
@@ -4520,6 +4619,7 @@ class KeyedCompleteTestType
45204619
m_double_field = x.m_double_field;
45214620
m_bool_field = x.m_bool_field;
45224621
m_string_field = std::move(x.m_string_field);
4622+
m_fixed_string_field = std::move(x.m_fixed_string_field);
45234623
m_enum_field = x.m_enum_field;
45244624
m_enum2_field = x.m_enum2_field;
45254625
m_struct_field = std::move(x.m_struct_field);
@@ -4603,6 +4703,7 @@ class KeyedCompleteTestType
46034703
m_double_field == x.m_double_field &&
46044704
m_bool_field == x.m_bool_field &&
46054705
m_string_field == x.m_string_field &&
4706+
m_fixed_string_field == x.m_fixed_string_field &&
46064707
m_enum_field == x.m_enum_field &&
46074708
m_enum2_field == x.m_enum2_field &&
46084709
m_struct_field == x.m_struct_field &&
@@ -5062,6 +5163,45 @@ class KeyedCompleteTestType
50625163
}
50635164

50645165

5166+
/*!
5167+
* @brief This function copies the value in member fixed_string_field
5168+
* @param _fixed_string_field New value to be copied in member fixed_string_field
5169+
*/
5170+
eProsima_user_DllExport void fixed_string_field(
5171+
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
5172+
{
5173+
m_fixed_string_field = _fixed_string_field;
5174+
}
5175+
5176+
/*!
5177+
* @brief This function moves the value in member fixed_string_field
5178+
* @param _fixed_string_field New value to be moved in member fixed_string_field
5179+
*/
5180+
eProsima_user_DllExport void fixed_string_field(
5181+
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
5182+
{
5183+
m_fixed_string_field = std::move(_fixed_string_field);
5184+
}
5185+
5186+
/*!
5187+
* @brief This function returns a constant reference to member fixed_string_field
5188+
* @return Constant reference to member fixed_string_field
5189+
*/
5190+
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
5191+
{
5192+
return m_fixed_string_field;
5193+
}
5194+
5195+
/*!
5196+
* @brief This function returns a reference to member fixed_string_field
5197+
* @return Reference to member fixed_string_field
5198+
*/
5199+
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
5200+
{
5201+
return m_fixed_string_field;
5202+
}
5203+
5204+
50655205
/*!
50665206
* @brief This function sets a value in member enum_field
50675207
* @param _enum_field New value for member enum_field
@@ -7398,6 +7538,7 @@ class KeyedCompleteTestType
73987538
double m_double_field{0.0};
73997539
bool m_bool_field{false};
74007540
std::string m_string_field;
7541+
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
74017542
Color m_enum_field{Color::RED};
74027543
Material m_enum2_field{Material::WOOD};
74037544
StructType m_struct_field;

0 commit comments

Comments
 (0)