From b8d7c62b8c0a5955799524231ca927634abfbbd2 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期一, 23 十月 2023 15:38:22 +0800
Subject: [PATCH] optimize json parse
---
funasr/runtime/websocket/bin/websocket-server.cpp | 10 +++++++++-
funasr/runtime/websocket/bin/websocket-server-2pass.cpp | 9 ++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/funasr/runtime/websocket/bin/websocket-server-2pass.cpp b/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
index b64cecb..9e0668f 100644
--- a/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
+++ b/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
@@ -356,7 +356,14 @@
unique_lock guard_decoder(*(thread_lock_p)); // mutex for one connection
switch (msg->get_opcode()) {
case websocketpp::frame::opcode::text: {
- nlohmann::json jsonresult = nlohmann::json::parse(payload);
+ nlohmann::json jsonresult;
+ try{
+ jsonresult = nlohmann::json::parse(payload);
+ }catch (std::exception const &e)
+ {
+ LOG(ERROR)<<e.what();
+ break;
+ }
if (jsonresult.contains("wav_name")) {
msg_data->msg["wav_name"] = jsonresult["wav_name"];
diff --git a/funasr/runtime/websocket/bin/websocket-server.cpp b/funasr/runtime/websocket/bin/websocket-server.cpp
index 6e1c211..134f5fa 100644
--- a/funasr/runtime/websocket/bin/websocket-server.cpp
+++ b/funasr/runtime/websocket/bin/websocket-server.cpp
@@ -256,7 +256,15 @@
unique_lock guard_decoder(*(thread_lock_p)); // mutex for one connection
switch (msg->get_opcode()) {
case websocketpp::frame::opcode::text: {
- nlohmann::json jsonresult = nlohmann::json::parse(payload);
+ nlohmann::json jsonresult;
+ try{
+ jsonresult = nlohmann::json::parse(payload);
+ }catch (std::exception const &e)
+ {
+ LOG(ERROR)<<e.what();
+ break;
+ }
+
if (jsonresult["wav_name"] != nullptr) {
msg_data->msg["wav_name"] = jsonresult["wav_name"];
}
--
Gitblit v1.9.1