Skip to content

[22851] Add support for bounded strings (backport #209) #210

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

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions fastdds_python/src/swig/fastcdr/cdr/fixed_size_string.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

%{
#include "fastcdr/cdr/fixed_size_string.hpp"
%}

// Ignore method that causes warnings on SWIG
%ignore eprosima::fastcdr::fixed_string::operator const char*() const;

%include "fastcdr/cdr/fixed_size_string.hpp"
1 change: 1 addition & 0 deletions fastdds_python/src/swig/fastdds.i
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace xtypes {
#ifndef FASTDDS_DOCS_BUILD
%include <fastcdr/config.h>
%include "fastcdr/xcdr/optional.i"
%include "fastcdr/cdr/fixed_size_string.i"
#endif

%include "fastdds/LibrarySettings.i"
Expand Down
7 changes: 7 additions & 0 deletions fastdds_python/test/api/test_datareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def fill_keyed_complete_test_type(data):
data.double_field(1202.5)
data.bool_field(True)
data.string_field("Test string")
fixed_string = pytest.dds_type.fixed_string_16("Fixed string")
data.fixed_string_field(fixed_string)
data.enum_field(pytest.dds_type.Color_MAGENTA)
data.enum2_field(pytest.dds_type.Material_METAL)
data.struct_field().char_field('\x01')
Expand All @@ -179,6 +181,7 @@ def fill_keyed_complete_test_type(data):
data.struct_field().double_field(1202.5)
data.struct_field().bool_field(False)
data.struct_field().string_field("Test string")
data.struct_field().fixed_string_field("Fixed string")
data.struct_field().enum_field(pytest.dds_type.Color_MAGENTA)
data.struct_field().enum2_field(pytest.dds_type.Material_METAL)
data.char_opt_field().set_value('\x01')
Expand Down Expand Up @@ -207,6 +210,7 @@ def fill_keyed_complete_test_type(data):
struct_field.double_field(1202.5)
struct_field.bool_field(True)
struct_field.string_field("Test string")
struct_field.fixed_string_field("Fixed string")
struct_field.enum_field(pytest.dds_type.Color_MAGENTA)
struct_field.enum2_field(pytest.dds_type.Material_METAL)
data.struct_opt_field().set_value(struct_field)
Expand Down Expand Up @@ -273,6 +277,7 @@ def check_keyed_complete_test_type(data):
assert(data.double_field() == 1202.5)
assert(data.bool_field() == True)
assert(data.string_field() == "Test string")
assert(data.fixed_string_field() == "Fixed string")
assert(data.enum_field() == pytest.dds_type.Color_MAGENTA)
assert(data.enum2_field() == pytest.dds_type.Material_METAL)
assert(data.struct_field().char_field() == '\x01')
Expand All @@ -287,6 +292,7 @@ def check_keyed_complete_test_type(data):
assert(data.struct_field().double_field() == 1202.5)
assert(data.struct_field().bool_field() == False)
assert(data.struct_field().string_field() == "Test string")
assert(data.struct_field().fixed_string_field() == "Fixed string")
assert(data.struct_field().enum_field() == pytest.dds_type.Color_MAGENTA)
assert(data.struct_field().enum2_field() == pytest.dds_type.Material_METAL)
assert(data.char_opt_field().has_value())
Expand Down Expand Up @@ -329,6 +335,7 @@ def check_keyed_complete_test_type(data):
assert(data.struct_opt_field().double_field() == 1202.5)
assert(data.struct_opt_field().bool_field() == True)
assert(data.struct_opt_field().string_field() == "Test string")
assert(data.struct_opt_field().fixed_string_field() == "Fixed string")
assert(data.struct_opt_field().enum_field() == pytest.dds_type.Color_MAGENTA)
assert(data.struct_opt_field().enum2_field() == pytest.dds_type.Material_METAL)
assert(data.array_char_field()[0] == '\x01')
Expand Down
141 changes: 141 additions & 0 deletions fastdds_python/test/types/test_complete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class StructType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -160,6 +162,7 @@ class StructType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_included_module_struct = std::move(x.m_included_module_struct);
Expand Down Expand Up @@ -197,6 +200,8 @@ class StructType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -226,6 +231,7 @@ class StructType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_included_module_struct = std::move(x.m_included_module_struct);
Expand All @@ -251,6 +257,7 @@ class StructType
m_double_field == x.m_double_field &&
m_bool_field == x.m_bool_field &&
m_string_field == x.m_string_field &&
m_fixed_string_field == x.m_fixed_string_field &&
m_enum_field == x.m_enum_field &&
m_enum2_field == x.m_enum2_field &&
m_included_module_struct == x.m_included_module_struct);
Expand Down Expand Up @@ -624,6 +631,45 @@ class StructType
}


/*!
* @brief This function copies the value in member fixed_string_field
* @param _fixed_string_field New value to be copied in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
{
m_fixed_string_field = _fixed_string_field;
}

/*!
* @brief This function moves the value in member fixed_string_field
* @param _fixed_string_field New value to be moved in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
{
m_fixed_string_field = std::move(_fixed_string_field);
}

/*!
* @brief This function returns a constant reference to member fixed_string_field
* @return Constant reference to member fixed_string_field
*/
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
{
return m_fixed_string_field;
}

/*!
* @brief This function returns a reference to member fixed_string_field
* @return Reference to member fixed_string_field
*/
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
{
return m_fixed_string_field;
}


/*!
* @brief This function sets a value in member enum_field
* @param _enum_field New value for member enum_field
Expand Down Expand Up @@ -736,6 +782,7 @@ class StructType
double m_double_field{0.0};
bool m_bool_field{false};
std::string m_string_field;
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
Color m_enum_field{Color::RED};
Material m_enum2_field{Material::WOOD};
eprosima::test2::StructType2 m_included_module_struct;
Expand Down Expand Up @@ -796,6 +843,8 @@ class CompleteTestType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -937,6 +986,7 @@ class CompleteTestType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_struct_field = std::move(x.m_struct_field);
Expand Down Expand Up @@ -1031,6 +1081,8 @@ class CompleteTestType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -1174,6 +1226,7 @@ class CompleteTestType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_struct_field = std::move(x.m_struct_field);
Expand Down Expand Up @@ -1256,6 +1309,7 @@ class CompleteTestType
m_double_field == x.m_double_field &&
m_bool_field == x.m_bool_field &&
m_string_field == x.m_string_field &&
m_fixed_string_field == x.m_fixed_string_field &&
m_enum_field == x.m_enum_field &&
m_enum2_field == x.m_enum2_field &&
m_struct_field == x.m_struct_field &&
Expand Down Expand Up @@ -1686,6 +1740,45 @@ class CompleteTestType
}


/*!
* @brief This function copies the value in member fixed_string_field
* @param _fixed_string_field New value to be copied in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
{
m_fixed_string_field = _fixed_string_field;
}

/*!
* @brief This function moves the value in member fixed_string_field
* @param _fixed_string_field New value to be moved in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
{
m_fixed_string_field = std::move(_fixed_string_field);
}

/*!
* @brief This function returns a constant reference to member fixed_string_field
* @return Constant reference to member fixed_string_field
*/
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
{
return m_fixed_string_field;
}

/*!
* @brief This function returns a reference to member fixed_string_field
* @return Reference to member fixed_string_field
*/
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
{
return m_fixed_string_field;
}


/*!
* @brief This function sets a value in member enum_field
* @param _enum_field New value for member enum_field
Expand Down Expand Up @@ -4021,6 +4114,7 @@ class CompleteTestType
double m_double_field{0.0};
bool m_bool_field{false};
std::string m_string_field;
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
Color m_enum_field{Color::RED};
Material m_enum2_field{Material::WOOD};
StructType m_struct_field;
Expand Down Expand Up @@ -4138,6 +4232,8 @@ class KeyedCompleteTestType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -4280,6 +4376,7 @@ class KeyedCompleteTestType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_struct_field = std::move(x.m_struct_field);
Expand Down Expand Up @@ -4376,6 +4473,8 @@ class KeyedCompleteTestType

m_string_field = x.m_string_field;

m_fixed_string_field = x.m_fixed_string_field;

m_enum_field = x.m_enum_field;

m_enum2_field = x.m_enum2_field;
Expand Down Expand Up @@ -4520,6 +4619,7 @@ class KeyedCompleteTestType
m_double_field = x.m_double_field;
m_bool_field = x.m_bool_field;
m_string_field = std::move(x.m_string_field);
m_fixed_string_field = std::move(x.m_fixed_string_field);
m_enum_field = x.m_enum_field;
m_enum2_field = x.m_enum2_field;
m_struct_field = std::move(x.m_struct_field);
Expand Down Expand Up @@ -4603,6 +4703,7 @@ class KeyedCompleteTestType
m_double_field == x.m_double_field &&
m_bool_field == x.m_bool_field &&
m_string_field == x.m_string_field &&
m_fixed_string_field == x.m_fixed_string_field &&
m_enum_field == x.m_enum_field &&
m_enum2_field == x.m_enum2_field &&
m_struct_field == x.m_struct_field &&
Expand Down Expand Up @@ -5062,6 +5163,45 @@ class KeyedCompleteTestType
}


/*!
* @brief This function copies the value in member fixed_string_field
* @param _fixed_string_field New value to be copied in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
const eprosima::fastcdr::fixed_string<16>& _fixed_string_field)
{
m_fixed_string_field = _fixed_string_field;
}

/*!
* @brief This function moves the value in member fixed_string_field
* @param _fixed_string_field New value to be moved in member fixed_string_field
*/
eProsima_user_DllExport void fixed_string_field(
eprosima::fastcdr::fixed_string<16>&& _fixed_string_field)
{
m_fixed_string_field = std::move(_fixed_string_field);
}

/*!
* @brief This function returns a constant reference to member fixed_string_field
* @return Constant reference to member fixed_string_field
*/
eProsima_user_DllExport const eprosima::fastcdr::fixed_string<16>& fixed_string_field() const
{
return m_fixed_string_field;
}

/*!
* @brief This function returns a reference to member fixed_string_field
* @return Reference to member fixed_string_field
*/
eProsima_user_DllExport eprosima::fastcdr::fixed_string<16>& fixed_string_field()
{
return m_fixed_string_field;
}


/*!
* @brief This function sets a value in member enum_field
* @param _enum_field New value for member enum_field
Expand Down Expand Up @@ -7398,6 +7538,7 @@ class KeyedCompleteTestType
double m_double_field{0.0};
bool m_bool_field{false};
std::string m_string_field;
eprosima::fastcdr::fixed_string<16> m_fixed_string_field;
Color m_enum_field{Color::RED};
Material m_enum2_field{Material::WOOD};
StructType m_struct_field;
Expand Down
Loading