You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/11/03 16:35:22 UTC

[geode-native] branch develop updated: GEODE-3728: Move DataOutput::writeFullUTF to TcrMessage

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new effc1e5  GEODE-3728: Move DataOutput::writeFullUTF to TcrMessage
effc1e5 is described below

commit effc1e50b5266ccb70ce9e3536543e024cba46b0
Author: David Kimura <dk...@pivotal.io>
AuthorDate: Thu Nov 2 16:14:22 2017 -0700

    GEODE-3728: Move DataOutput::writeFullUTF to TcrMessage
---
 cppcache/include/geode/DataOutput.hpp | 23 -----------------------
 cppcache/src/TcrMessage.cpp           | 28 +++++++++++++++++++++++++++-
 cppcache/test/DataOutputTest.cpp      |  8 --------
 3 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/cppcache/include/geode/DataOutput.hpp b/cppcache/include/geode/DataOutput.hpp
index 47a465b..6bc91e0 100644
--- a/cppcache/include/geode/DataOutput.hpp
+++ b/cppcache/include/geode/DataOutput.hpp
@@ -336,29 +336,6 @@ class CPPCACHE_EXPORT DataOutput {
   }
 
   /**
-   * Writes the given string using java modified UTF-8 encoding
-   * supporting maximum 32-bit unsigned integer.
-   *
-   * @param value the C string to be written
-   *
-   */
-  inline void writeFullUTF(const char* value, uint32_t length = 0) {
-    if (value != nullptr) {
-      int32_t encodedLen = getEncodedLength(value, length);
-      writeInt(encodedLen);
-      ensureCapacity(encodedLen);
-      write(static_cast<int8_t>(0));  // isObject = 0 BYTE_CODE
-      uint8_t* end = m_buf + encodedLen;
-      while (m_buf < end) {
-        encodeChar(*value++);
-      }
-      if (m_buf > end) m_buf = end;
-    } else {
-      writeInt(static_cast<uint16_t>(0));
-    }
-  }
-
-  /**
    * Writes the given given string using java modified UTF-8 encoding
    * supporting maximum encoded length of 64K (i.e. unsigned 16-bit integer).
    * @remarks The string will be truncated if greater than the maximum
diff --git a/cppcache/src/TcrMessage.cpp b/cppcache/src/TcrMessage.cpp
index 066ddf7..bd79f54 100644
--- a/cppcache/src/TcrMessage.cpp
+++ b/cppcache/src/TcrMessage.cpp
@@ -656,7 +656,33 @@ void TcrMessage::writeRegionPart(const std::string& regionName) {
 }
 
 void TcrMessage::writeStringPart(const std::string& str) {
-  m_request->writeFullUTF(str.c_str());
+  const char* value = str.c_str();
+  uint32_t length = 0;
+  if (value != nullptr) {
+    int32_t encodedLen = m_request->getEncodedLength(value, length);
+    m_request->writeInt(encodedLen);
+    m_request->ensureCapacity(encodedLen);
+    m_request->write(static_cast<int8_t>(0));  // isObject = 0 BYTE_CODE
+    const uint8_t* end = m_request->getCursor() + encodedLen;
+
+    while (m_request->getCursor() < end) {
+      uint8_t tmp = static_cast<uint8_t>(*value++);
+      if ((tmp == 0) || (tmp & 0x80)) {
+        // two byte.
+        m_request->write(static_cast<uint8_t>(0xc0 | ((tmp & 0xc0) >> 6)));
+        m_request->write(static_cast<uint8_t>(0x80 | (tmp & 0x3f)));
+      } else {
+        // one byte.
+        m_request->write(tmp);
+      }
+    }
+    if (m_request->getCursor() > end) {
+      uint32_t offset = m_request->getCursor() - end;
+      m_request->rewindCursor(offset);
+    }
+  } else {
+    m_request->writeInt(static_cast<uint16_t>(0));
+  }
 }
 
 void TcrMessage::writeEventIdPart(int reserveSize,
diff --git a/cppcache/test/DataOutputTest.cpp b/cppcache/test/DataOutputTest.cpp
index 48a8936..a27cc0a 100644
--- a/cppcache/test/DataOutputTest.cpp
+++ b/cppcache/test/DataOutputTest.cpp
@@ -239,14 +239,6 @@ TEST_F(DataOutputTest, TestWriteASCIIHuge) {
       dataOutput.getByteArray());
 }
 
-TEST_F(DataOutputTest, TestWriteFullUTF) {
-  TestDataOutput dataOutput(nullptr);
-  dataOutput.writeFullUTF("You had me at meat tornado.");
-  EXPECT_BYTEARRAY_EQ(
-      "0000001B00596F7520686164206D65206174206D65617420746F726E61646F2E",
-      dataOutput.getByteArray());
-}
-
 TEST_F(DataOutputTest, TestWriteUTF) {
   TestDataOutput dataOutput(nullptr);
   dataOutput.writeUTF("You had me at meat tornado.");

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].