Skip to content

Commit

Permalink
feat(third_party): Added Fast-CDR-v2.2.2 patch file
Browse files Browse the repository at this point in the history
  • Loading branch information
minhanghuang committed Jan 18, 2025
1 parent 8e025e7 commit bca7c59
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def _clone_dds2(self):
os.chdir(self._current_path)

os.chdir(os.path.join(self._dowload_path, "Fast-CDR"))
self._cmd("patch -p1 < {}".format(os.path.join(self._current_path,"scripts/Fast-CDR_v2.2.2.patch")))
self._cmd("mkdir -p build")
os.chdir("build")
self._cmd("cmake -DCMAKE_INSTALL_PREFIX={} -DBUILD_SHARED_LIBS=ON ..".format(
Expand Down
75 changes: 75 additions & 0 deletions scripts/Fast-CDR_v2.2.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h
index ba51fa2..d90dafb 100644
--- a/include/fastcdr/Cdr.h
+++ b/include/fastcdr/Cdr.h
@@ -689,6 +689,9 @@ public:
Cdr_DllAPI Cdr& serialize(
const char* string_t);

+ Cdr_DllAPI Cdr& serialize(
+ const char* string_t, size_t str_length);
+
/*!
* @brief This function serializes a wstring.
* @param string_t The pointer to the wstring that will be serialized in the buffer.
@@ -708,7 +711,7 @@ public:
Cdr& serialize(
const std::string& string_t)
{
- return serialize(string_t.c_str());
+ return serialize(string_t.c_str(), string_t.size());
}

/*!
diff --git a/src/cpp/Cdr.cpp b/src/cpp/Cdr.cpp
index 189ee21..3d1a5a5 100644
--- a/src/cpp/Cdr.cpp
+++ b/src/cpp/Cdr.cpp
@@ -813,6 +813,47 @@ Cdr& Cdr::serialize(
return *this;
}

+Cdr& Cdr::serialize(
+ const char* string_t, size_t str_length)
+{
+ uint32_t length = 0;
+
+ if (string_t != nullptr)
+ {
+ // length = size_to_uint32(strlen(string_t)) + 1;
+ length = (uint32_t)str_length + 1;
+ }
+
+ if (length > 0)
+ {
+ Cdr::state state_before_error(*this);
+ serialize(length);
+
+ if (((end_ - offset_) >= length) || resize(length))
+ {
+ // Save last datasize.
+ last_data_size_ = sizeof(uint8_t);
+
+ offset_.memcopy(string_t, length);
+ offset_ += length;
+ }
+ else
+ {
+ set_state(state_before_error);
+ throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
+ }
+ }
+ else
+ {
+ serialize(length);
+ }
+
+ serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
+
+ return *this;
+}
+
+
Cdr& Cdr::serialize(
const wchar_t* string_t)
{

1 comment on commit bca7c59

@minhanghuang
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#84

Please sign in to comment.