You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/07/03 10:48:19 UTC

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #596: MINIFICPP-925 - Fix TailFile hang on long lines

arpadboda commented on a change in pull request #596: MINIFICPP-925 - Fix TailFile hang on long lines
URL: https://github.com/apache/nifi-minifi-cpp/pull/596#discussion_r299891342
 
 

 ##########
 File path: libminifi/include/utils/StringUtils.h
 ##########
 @@ -347,6 +227,139 @@ class StringUtils {
     return join(std::basic_string<TChar>(separator), container);
   };
 
+  /**
+   * Hexdecodes the hexencoded string in data, ignoring every character that is not [0-9a-fA-F]
+   * @param data the output buffer where the hexdecoded bytes will be written. Must be at least length / 2 bytes long.
+   * @param data_length pointer to the length of data the data buffer. It will be filled with the length of the decoded bytes.
+   * @param hex the hexencoded string
+   * @param hex_length the length of hex
+   * @return true on success
+   */
+  inline static bool from_hex(uint8_t* data, size_t* data_length, const char* hex, size_t hex_length) {
+    if (*data_length < hex_length / 2) {
+      return false;
+    }
+    uint8_t n1;
+    bool found_first_nibble = false;
+    *data_length = 0;
+    for (size_t i = 0; i < hex_length; i++) {
+      const uint8_t byte = static_cast<uint8_t>(hex[i]);
+      if (byte > 127) {
+        continue;
+      }
+      uint8_t n = hex_lut[byte];
+      if (n != SKIP) {
+        if (found_first_nibble) {
+          data[(*data_length)++] = n1 << 4 | n;
+          found_first_nibble = false;
+        } else {
+          n1 = n;
+          found_first_nibble = true;
+        }
+      }
+    }
+    if (found_first_nibble) {
 
 Review comment:
   Simply return this? :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services