From b857329adeed41a776746a6bd9d4879a57ce421d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 6 Nov 2024 11:51:13 +0100 Subject: [PATCH] Refs #21362. Leave implementation in header. Signed-off-by: Miguel Company --- include/fastcdr/Cdr.h | 21 +++++++++++++++++++-- src/cpp/Cdr.cpp | 21 --------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index e99803f4..681ae918 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -705,9 +705,26 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. * @exception exception::BadParamException This exception is thrown when trying to serialize a string with null characters. */ - TEMPLATE_SPEC Cdr_DllAPI + TEMPLATE_SPEC Cdr& serialize( - const std::string& string_t); + const std::string& string_t) + { + // An empty string is serialized as a 0 length string. + if (string_t.empty()) + { + return serialize(static_cast(0)); + } + + // Check there are no null characters in the string. + const char* c_str = string_t.c_str(); + const auto str_len = strlen(c_str); + if (string_t.size() > str_len) + { + throw BadParamException("The string contains null characters"); + } + + return serialize_sequence(c_str, str_len + 1); + } /*! * @brief This function serializes a std::wstring. diff --git a/src/cpp/Cdr.cpp b/src/cpp/Cdr.cpp index b79f2d25..b050796e 100644 --- a/src/cpp/Cdr.cpp +++ b/src/cpp/Cdr.cpp @@ -887,27 +887,6 @@ Cdr& Cdr::serialize( return *this; } -TEMPLATE_SPEC -Cdr& Cdr::serialize( - const std::string& string_t) -{ - // An empty string is serialized as a 0 length string. - if (string_t.empty()) - { - return serialize(static_cast(0)); - } - - // Check there are no null characters in the string. - const char* c_str = string_t.c_str(); - const auto str_len = strlen(c_str); - if (string_t.size() > str_len) - { - throw BadParamException("The string contains null characters"); - } - - return serialize_sequence(c_str, str_len + 1); -} - Cdr& Cdr::serialize_array( const bool* bool_t, size_t num_elements)