chenpeng 5 meses atrás
pai
commit
7fea6a908c
2 arquivos alterados com 28 adições e 0 exclusões
  1. 23 0
      CommonFunction.hpp
  2. 5 0
      DemoProtocol.cpp

+ 23 - 0
CommonFunction.hpp

@@ -149,6 +149,29 @@ static uint64_t get_timestamp_from_vec(const uint8_t* szData,const size_t size)
     return timestamp;
 }
 
+// 去掉字符串中的"${}"部分
+static std::string removeBraces(const std::string& input) {
+    std::string result;
+    size_t startPos = 0;
+    size_t foundPos = input.find("${", startPos); // 查找"${"的位置
+
+    while (foundPos != std::string::npos) {
+        // 将"${"之前的部分拼接到结果中
+        result += input.substr(startPos, foundPos - startPos);
+        
+        // 更新起始位置,跳过"${"
+        startPos = foundPos + 2;
+
+        // 查找下一个"${"的位置
+        foundPos = input.find("${", startPos);
+    }
+
+    // 将最后一个"${"之后的部分拼接到结果中
+    result += input.substr(startPos);
+
+    return result;
+}
+
 //获取%{}中的数值
 static std::vector<std::string> extractValueFromExpression(const std::string& expression)
 {

+ 5 - 0
DemoProtocol.cpp

@@ -1385,6 +1385,11 @@ void DemoProtocol::unpack_bridge_data(memepp::string_view data)
         // 将剩下的内容转换为json
         nlohmann::json jsonObj = nlohmann::json::parse(jsonStr);
         for (const auto& entry : jsonObj.items()) {
+            auto value = jsonObj[entry.key()].get<std::string>();
+            if (!value.empty())
+            {
+                value = removeBraces(value);
+            }
             point_bridge_map_[entry.key()] = jsonObj[entry.key()].get<std::string>();
             cmnproto_log_debug(m_handle.native(), "bridge data: %s = %s", entry.key().c_str(), entry.value().get<std::string>().c_str());
         }